# Gather rows into columns

Shape / table

flatten a row group into columns, or spread columns back to rows

Page: <https://meridian.online/operations/gather-rows-into-columns>

## Status

Runs as a SQL step.

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

## The DuckDB step

flatten a row group into columns

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 customer, list(product ORDER BY order_date) AS products,
       products[1] AS first_product, products[2] AS second_product
FROM orders GROUP BY customer;
SELECT * FROM result ORDER BY ALL;
SELECT CASE WHEN ((SELECT count(*) = 8 AND max(first_product) FILTER (WHERE customer = 'Alice Ng') = 'widget' AND max(second_product) FILTER (WHERE customer = 'Alice Ng') = 'gizmo' FROM result)) THEN 'as expected' ELSE error('the orders of one customer did not flatten in date order') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## Variants

- Gather key-value rows into columns: Turn rows of keys and values into one row per group with a column per key.
- Flatten consecutive rows into one: Gather every N consecutive rows, or each run of rows, into the columns of a single row.
- Treat row groups as records: Treat the rows under one leading value as one record, so later operations apply per record.
- Spread repeated columns back into rows: Turn a set of repeated columns into one row per column, with a type field and value fields.

## What other tools call it

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

- Alteryx Designer: [`Make Columns`](https://help.alteryx.com/current/en/designer/tools/transform/make-columns-tool.html) (read 2026-09-27)
- Apache Hop: [`Row Denormaliser`](https://hop.apache.org/manual/latest/pipeline/transforms/rowdenormaliser.html) (read 2026-09-27)
- Apache Hop: [`Row Flattener`](https://hop.apache.org/manual/latest/pipeline/transforms/rowflattener.html) (read 2026-09-27)
- Apache Hop: [`Row Normaliser`](https://hop.apache.org/manual/latest/pipeline/transforms/rownormaliser.html) (read 2026-09-27)
- KNIME Analytics Platform: [`Column to Grid`](https://api.hub.knime.com/nodes/*MyUFTQuDjqnjlyto?details=full) (read 2026-09-27)
- OpenRefine: [`Show as records`](https://openrefine.org/docs/manual/exploring#rows-vs-records) (read 2026-09-27)
- OpenRefine: [`Transpose cells in rows into columns…`](https://openrefine.org/docs/manual/transposing#transpose-cells-in-rows-into-columns) (read 2026-09-27)
- Pentaho Data Integration: [`Row Denormaliser`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Pentaho Data Integration: [`Row Flattener`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
- Pentaho Data Integration: [`Row Normaliser`](https://docs.pentaho.com/pdia-data-integration/9.3-data-integration/pdi-transformation-steps-reference-overview) (read 2026-09-27)
