---
title: "ntile window function in Strata | Oplema"
description: "Divide ordered rows into a number of roughly equal groups, numbered from 1. Write it in a Strata Formula, such as ntile(2) OVER (ORDER BY id)."
url: "https://oplema.com/docs/strata/functions/ntile"
updated: "2026-11-04"
---

# ntile

Divide ordered rows into a requested number of approximately equal groups.

## Try an expression

In [Formula](https://oplema.com/docs/strata/prep/formula), enter the expression and set Output type to **BIGINT**.

Example input

1. Row 1 `id = 1, amount = 10`
2. Row 2 `id = 2, amount = NULL`
3. Row 3 `id = 3, amount = 30`
4. Row 4 `id = 4, amount = 30`

### Expression

```
ntile(2) OVER (ORDER BY id)
```

### Result

```
Row 1: 1
Row 2: 1
Row 3: 2
Row 4: 2
```

NULL means the value is missing.

Try it live in Formula

Result
| id | amount | result |
| --- | --- | --- |
| 1 | 10 | 1 |
| 2 |  | 1 |
| 3 | 30 | 2 |
| 4 | 30 | 2 |

## Arguments and types

```
ntile(num_buckets[ ORDER BY ordering])
```

The result type can depend on the input types. See DuckDB for the full argument rules.

## Things to know

ORDER BY defines the order used by the calculation; it doesn't sort the output table. Include a unique tie-breaker when row position matters. Window expressions belong in Formula and can't be entered directly in Filter.

## Related functions

[cume\_dist

Find the fraction of rows whose sort value is less than or equal to the current value.

](https://oplema.com/docs/strata/functions/cume-dist)[row\_number

Number rows in a specified order.

](https://oplema.com/docs/strata/functions/row-number)[fill

Estimate missing values using linear interpolation along an ordered sequence.

](https://oplema.com/docs/strata/functions/fill)[dense\_rank

Rank distinct values consecutively, giving ties the same rank.

](https://oplema.com/docs/strata/functions/dense-rank)

[Browse across rows](https://oplema.com/docs/strata/functions#across-rows) [DuckDB documentation](https://duckdb.org/docs/current/sql/functions/window_functions.html#ntilenum_buckets-order-by-ordering)

Function metadata from DuckDB, used under the [MIT license](https://github.com/duckdb/duckdb/blob/v1.5.4/LICENSE).
