# Rank rows

Shape / rows

A variant of [Number or rank rows](https://meridian.online/operations/number-or-rank-rows).

Add a column giving each row its rank by one or more ordering columns, with ties sharing a rank.

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

## Status

Runs as a SQL step.

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

## The DuckDB step

rank rows by one or more columns, with ties sharing a rank

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 ranked AS
SELECT order_id, region, amount,
       rank() OVER (ORDER BY amount DESC NULLS LAST) AS by_amount,
       dense_rank() OVER (ORDER BY amount DESC NULLS LAST) AS by_amount_dense,
       rank() OVER (ORDER BY region NULLS LAST, amount DESC NULLS LAST) AS by_region_amount
FROM orders;
SELECT * FROM ranked ORDER BY order_id;
SELECT CASE WHEN ((SELECT list(by_amount ORDER BY order_id) FROM ranked) = [5, 7, 3, 10, 8, 1, 6, 1, 9, 4] AND (SELECT list(by_amount_dense ORDER BY order_id) FROM ranked) = [4, 6, 2, 9, 7, 1, 5, 1, 8, 3] AND (SELECT list(by_region_amount ORDER BY order_id) FROM ranked) = [4, 5, 6, 2, 7, 8, 1, 8, 10, 3]) THEN 'as expected' ELSE error('the ranks did not give the two 510.00 orders the same rank, or did not order ties on a second column') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## What other tools call it

Meridian's classification; an independent blind rating agreed on 95.7% of 324 rows (variant, version 3).

- Azure Data Factory: [`Rank`](https://learn.microsoft.com/en-us/azure/data-factory/data-flow-rank) (read 2026-09-27)
- Alteryx Designer: [`Rank`](https://help.alteryx.com/current/en/designer/tools/preparation/rank-tool.html) (read 2026-09-27)
- Bruin: [`rank`](https://getbruin.com/docs/bruin/core-concepts/semantic-layer.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: [`rank`](https://datafusion.apache.org/user-guide/sql/window_functions.html) (read 2026-09-27)
- DuckDB: [`dense_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)
- Duckle: [`Dense Rank`](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)
- EasyMorph: [`Enumerate groups`](https://help.easymorph.com/doku.php?id=transformations:enumerategroups) (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)
- KNIME Analytics Platform: [`Rank`](https://api.hub.knime.com/nodes/*-nXP9ULsMFxDeH3m?details=full) (read 2026-09-27)
- Polars: [`Expr.rank`](https://docs.pola.rs/api/python/stable/reference/expressions/computation.html) (read 2026-09-27)
- Power Query M: [`Table.AddRankColumn`](https://learn.microsoft.com/en-us/powerquery-m/table-functions#ordering) (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`](https://help.tableau.com/current/prep/en-us/prep_calculations.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)
- VisiData: [`addcol-rank-sheet`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/rank.py#L106) (read 2026-09-23)
