# Number or rank rows

Shape / rows

row number, record id, rank, dense rank, ntile

Page: <https://meridian.online/operations/number-or-rank-rows>

## Status

Runs as a SQL step.

arcform carries it as a `sql:` step today.

## The DuckDB step

row number, rank and quartile

It reads the `orders` table the proofs share. Create it first:

```sql
CREATE TABLE orders AS SELECT * FROM (VALUES
  (1,  'Alice Ng',      'north', DATE '2026-01-03', 120.00, 'widget', 'a|b',   '{"channel":"web","items":[1,2]}'),
  (2,  'alice ng',      'north', DATE '2026-01-05',  80.50, 'gadget', 'b',     '{"channel":"shop","items":[3]}'),
  (3,  'Bob  Okafor',   'south', DATE '2026-01-05', 300.00, 'widget', 'a|c',   '{"channel":"web","items":[4,5,6]}'),
  (4,  'Carla Díaz',    'east',  DATE '2026-01-09',  NULL,  'gizmo',  NULL,    '{"channel":"web","items":[]}'),
  (5,  'Bob Okafor',    'south', DATE '2026-01-12',  45.25, 'gadget', 'c',     '{"channel":"phone","items":[7]}'),
  (6,  'Dev Patel',     'west',  DATE '2026-01-12', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (7,  'Carla Diaz',    'east',  DATE '2026-01-20',  99.99, 'gizmo',  'b|c',   '{"channel":"shop","items":[10]}'),
  (8,  'Dev Patel',     'west',  DATE '2026-02-02', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (9,  'Eve Larsen',    NULL,    DATE '2026-02-03',  15.00, 'gadget', NULL,    '{"channel":"web","items":[11]}'),
  (10, 'Alice Ng',      'north', DATE '2026-02-10', 220.00, 'gizmo',  'a|b|c', '{"channel":"phone","items":[12,13]}')
) t(order_id, customer, region, order_date, amount, product, tags, meta);
```

Then run the statement:

```sql
CREATE TEMP TABLE result AS
SELECT order_id, amount,
       row_number() OVER (ORDER BY order_id) AS rn,
       dense_rank() OVER (ORDER BY amount DESC NULLS LAST) AS amount_rank,
       ntile(4) OVER (ORDER BY amount) AS quartile
FROM orders;
SELECT * FROM result;
SELECT CASE WHEN ((SELECT count(*) FILTER (WHERE amount = 510 AND amount_rank = 1) = 2 AND max(rn) = 10 AND count(DISTINCT quartile) = 4 FROM result)) THEN 'as expected' ELSE error('the two largest orders do not share rank 1, or the numbering is wrong') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## Variants

- Flag the last row: Add a flag that is true only on the last row of the stream.
- [Split rows into equal buckets](https://meridian.online/operations/number-or-rank-rows/split-rows-into-equal-buckets): Assign each row to one of N buckets of equal size, in order.
- Find the position of a row: Return the row positions at which given rows occur in a table.
- [Percentile rank](https://meridian.online/operations/number-or-rank-rows/percentile-rank): Give each row its relative position within its partition as a fraction from 0 to 1.
- [Rank rows](https://meridian.online/operations/number-or-rank-rows/rank-rows): Add a column giving each row its rank by one or more ordering columns, with ties sharing a rank.
- Number rows in order: Add a column counting the rows from a start value, in their order or within groups, from a counter or a sequence.
- [Number runs of equal values](https://meridian.online/operations/number-or-rank-rows/number-runs-of-equal-values): Add a number that restarts, or an id that changes, whenever the value of chosen columns changes from one row to the next.
- [Add a unique id](https://meridian.online/operations/number-or-rank-rows/add-a-unique-id): Add a column holding a random, hashed or time-ordered identifier that is unique to each row and does not depend on row order.

## What other tools call it

Meridian's classification; an independent blind rating agreed on 86.2% of 312 rows (exact class, version 2).

- Azure Data Factory: [`Rank`](https://learn.microsoft.com/en-us/azure/data-factory/data-flow-rank) (read 2026-09-27)
- Azure Data Factory: [`Surrogate key`](https://learn.microsoft.com/en-us/azure/data-factory/data-flow-surrogate-key) (read 2026-09-27)
- Alteryx Designer: [`Rank`](https://help.alteryx.com/current/en/designer/tools/preparation/rank-tool.html) (read 2026-09-27)
- Alteryx Designer: [`Record ID`](https://help.alteryx.com/current/en/designer/tools/preparation/record-id-tool.html) (read 2026-09-27)
- Bruin: [`rank`](https://getbruin.com/docs/bruin/core-concepts/semantic-layer.html) (read 2026-09-27)
- Apache DataFusion: [`cume_dist`](https://datafusion.apache.org/user-guide/sql/window_functions.html) (read 2026-09-27)
- Apache DataFusion: [`dense_rank`](https://datafusion.apache.org/user-guide/sql/window_functions.html) (read 2026-09-27)
- Apache DataFusion: [`ntile`](https://datafusion.apache.org/user-guide/sql/window_functions.html) (read 2026-09-27)
- Apache DataFusion: [`percent_rank`](https://datafusion.apache.org/user-guide/sql/window_functions.html) (read 2026-09-27)
- Apache DataFusion: [`rank`](https://datafusion.apache.org/user-guide/sql/window_functions.html) (read 2026-09-27)
- Apache DataFusion: [`row_number`](https://datafusion.apache.org/user-guide/sql/window_functions.html) (read 2026-09-27)
- DuckDB: [`CREATE SEQUENCE`](https://duckdb.org/docs/current/sql/statements/create_sequence) (read 2026-09-27)
- DuckDB: [`cume_dist`](https://duckdb.org/docs/current/sql/functions/window_functions) (read 2026-09-27)
- DuckDB: [`dense_rank`](https://duckdb.org/docs/current/sql/functions/window_functions) (read 2026-09-27)
- DuckDB: [`ntile`](https://duckdb.org/docs/current/sql/functions/window_functions) (read 2026-09-27)
- DuckDB: [`percent_rank`](https://duckdb.org/docs/current/sql/functions/window_functions) (read 2026-09-27)
- DuckDB: [`rank`](https://duckdb.org/docs/current/sql/functions/window_functions) (read 2026-09-27)
- DuckDB: [`rank_dense`](https://duckdb.org/docs/current/sql/functions/window_functions) (read 2026-09-27)
- DuckDB: [`row_number`](https://duckdb.org/docs/current/sql/functions/window_functions) (read 2026-09-27)
- Duckle: [`Dense Rank`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- Duckle: [`NTile`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- Duckle: [`Rank`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- Duckle: [`Row Number`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- Duckle: [`Surrogate Key`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/frontend/src/workflow-ui/palette-data.ts) (read 2026-09-25)
- Duckle: [`UUID`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- EasyMorph: [`Enumerate groups`](https://help.easymorph.com/doku.php?id=transformations:enumerategroups) (read 2026-09-27)
- EasyMorph: [`Enumerate rows`](https://help.easymorph.com/doku.php?id=transformations:enumerate) (read 2026-09-27)
- EasyMorph: [`Generate unique identifiers`](https://help.easymorph.com/doku.php?id=transformations:generateuids) (read 2026-09-27)
- AWS Glue: [`Identifier`](https://docs.aws.amazon.com/glue/latest/dg/transforms-identifier.html) (read 2026-09-27)
- AWS Glue: [`UUID`](https://docs.aws.amazon.com/glue/latest/dg/transforms-uuid.html) (read 2026-09-27)
- Apache Hop: [`Add Sequence`](https://hop.apache.org/manual/latest/pipeline/transforms/addsequence.html) (read 2026-09-27)
- Apache Hop: [`Add value fields changing sequence`](https://hop.apache.org/manual/latest/pipeline/transforms/addfieldschangesequence.html) (read 2026-09-27)
- Apache Hop: [`Identify last row in a stream`](https://hop.apache.org/manual/latest/pipeline/transforms/identifylastrow.html) (read 2026-09-27)
- Apache Hop: [`Snowflake ID Generator`](https://hop.apache.org/manual/latest/pipeline/transforms/snowflakeid.html) (read 2026-09-27)
- Ibis: [`CumeDist`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/analytic.py) (read 2026-09-27)
- Ibis: [`DenseRank`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/analytic.py) (read 2026-09-27)
- Ibis: [`MinRank`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/analytic.py) (read 2026-09-27)
- Ibis: [`NTile`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/analytic.py) (read 2026-09-27)
- Ibis: [`PercentRank`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/analytic.py) (read 2026-09-27)
- Ibis: [`RandomUUID`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/generic.py) (read 2026-09-27)
- Ibis: [`RowID`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/generic.py) (read 2026-09-27)
- Ibis: [`RowNumber`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/analytic.py) (read 2026-09-27)
- KNIME Analytics Platform: [`Rank`](https://api.hub.knime.com/nodes/*-nXP9ULsMFxDeH3m?details=full) (read 2026-09-27)
- KNIME Analytics Platform: [`RowID`](https://api.hub.knime.com/nodes/*1Uo48m8MIHW-seLx?details=full) (read 2026-09-27)
- Pentaho Data Integration: [`Add sequence`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Pentaho Data Integration: [`Add value fields changing sequence`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Pentaho Data Integration: [`Get ID from slave server`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Pentaho Data Integration: [`Identify last row in a stream`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Polars: [`DataFrame.with_row_count`](https://docs.pola.rs/api/python/stable/reference/dataframe/modify_select.html) (read 2026-09-27)
- Polars: [`DataFrame.with_row_index`](https://docs.pola.rs/api/python/stable/reference/dataframe/modify_select.html) (read 2026-09-27)
- Polars: [`Expr.rank`](https://docs.pola.rs/api/python/stable/reference/expressions/computation.html) (read 2026-09-27)
- Polars: [`Expr.rle_id`](https://docs.pola.rs/api/python/stable/reference/expressions/modify_select.html) (read 2026-09-27)
- Polars: [`row_index`](https://docs.pola.rs/api/python/stable/reference/expressions/functions.html) (read 2026-09-27)
- Power Query M: [`Table.AddIndexColumn`](https://learn.microsoft.com/en-us/powerquery-m/table-functions#transformation) (read 2026-09-27)
- Power Query M: [`Table.AddRankColumn`](https://learn.microsoft.com/en-us/powerquery-m/table-functions#ordering) (read 2026-09-27)
- Power Query M: [`Table.PositionOf`](https://learn.microsoft.com/en-us/powerquery-m/table-functions#membership) (read 2026-09-27)
- Power Query M: [`Table.PositionOfAny`](https://learn.microsoft.com/en-us/powerquery-m/table-functions#membership) (read 2026-09-27)
- RapidMiner Studio: [`Generate Batch`](https://docs.rapidminer.com/latest/studio/operators/blending/attributes/generation/generate_batch.html) (read 2026-09-27)
- RapidMiner Studio: [`Generate ID`](https://docs.rapidminer.com/latest/studio/operators/blending/attributes/generation/generate_id.html) (read 2026-09-27)
- RapidMiner Studio: [`Generate Rank (In Database)`](https://docs.rapidminer.com/latest/studio/operators/extensions/In-Database%20Processing/indb_blending/indb_generate_rank.html) (read 2026-09-27)
- Tableau Prep: [`RANK`](https://help.tableau.com/current/prep/en-us/prep_function_reference.htm) (read 2026-09-27)
- Tableau Prep: [`RANK_DENSE`](https://help.tableau.com/current/prep/en-us/prep_function_reference.htm) (read 2026-09-27)
- Tableau Prep: [`RANK_MODIFIED`](https://help.tableau.com/current/prep/en-us/prep_function_reference.htm) (read 2026-09-27)
- Tableau Prep: [`RANK_PERCENTILE`](https://help.tableau.com/current/prep/en-us/prep_function_reference.htm) (read 2026-09-27)
- Tableau Prep: [`ROW_NUMBER`](https://help.tableau.com/current/prep/en-us/prep_function_reference.htm) (read 2026-09-27)
- Tableau Prep: [`Rank`](https://help.tableau.com/current/prep/en-us/prep_calculations.htm) (read 2026-09-27)
- Tableau Prep: [`Source Row Number`](https://help.tableau.com/current/prep/en-us/prep_configure_dastaset.htm) (read 2026-09-27)
- Trifacta: [`DENSERANK Function`](https://help.alteryx.com/aac/en/trifacta-classic/wrangle-language/window-functions.html) (read 2026-09-27)
- Trifacta: [`RANK Function`](https://help.alteryx.com/aac/en/trifacta-classic/wrangle-language/window-functions.html) (read 2026-09-27)
- Trifacta: [`ROWNUMBER Function`](https://help.alteryx.com/aac/en/trifacta-classic/wrangle-language/window-functions.html) (read 2026-09-27)
- Trifacta: [`sourcerownumber`](https://help.alteryx.com/aac/en/trifacta-classic/reference/transformation-reference.html) (read 2026-09-27)
- VisiData: [`addcol-incr`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/incr.py#L41) (read 2026-09-23)
- VisiData: [`addcol-incr-key`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/incr.py#L40) (read 2026-09-23)
- VisiData: [`addcol-incr-step`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/incr.py#L43) (read 2026-09-23)
- VisiData: [`addcol-rank-sheet`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/rank.py#L106) (read 2026-09-23)
- VisiData: [`addcol-rownum`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/experimental/rownum.py#L72) (read 2026-09-23)
- VisiData: [`setcol-incr`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/incr.py#L42) (read 2026-09-23)
- VisiData: [`setcol-incr-step`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/incr.py#L44) (read 2026-09-23)
