# Transpose a table

Shape / table

swap rows and columns

Page: <https://meridian.online/operations/transpose-a-table>

## Status

Runs as a SQL step.

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

## The DuckDB step

swap rows and columns

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

```sql
CREATE TABLE customers AS SELECT * FROM (VALUES
  ('Alice Ng',    'retail',    DATE '2025-06-01', 52.52, 13.40),
  ('Bob Okafor',  'wholesale', DATE '2025-09-15', 48.85,  2.35),
  ('Carla Diaz',  'retail',    DATE '2025-11-30', 40.42, -3.70),
  ('Frank Moore', 'retail',    DATE '2026-01-01', 51.51, -0.13)
) t(customer, segment, joined, lat, lon);
```

Then run the statement:

```sql
CREATE TEMP TABLE result AS
PIVOT (UNPIVOT (SELECT customer, lat, lon FROM customers) ON lat, lon INTO NAME measure VALUE reading)
ON customer USING first(reading) GROUP BY measure;
SELECT * FROM result ORDER BY ALL;
SELECT CASE WHEN ((SELECT count(*) = 2 AND max("Alice Ng") FILTER (WHERE measure = 'lat') = 52.52 AND max("Frank Moore") FILTER (WHERE measure = 'lon') = -0.13 FROM result)) THEN 'as expected' ELSE error('the customers did not become columns and the measures rows') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## What other tools call it

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

- Duckle: [`Transpose`](https://github.com/slothflowlabs/duckle/blob/f85f8960edfb6efbf4cb89d58a7b32e16df0e867/website/docs/components.html) (read 2026-09-25)
- KNIME Analytics Platform: [`Table Transposer`](https://api.hub.knime.com/nodes/*rqhXsa-dMez9coq4?details=full) (read 2026-09-27)
- Polars: [`DataFrame.transpose`](https://docs.pola.rs/api/python/stable/reference/dataframe/modify_select.html) (read 2026-09-27)
- Power Query M: [`Table.Transpose`](https://learn.microsoft.com/en-us/powerquery-m/table-functions#transformation) (read 2026-09-27)
- RapidMiner Studio: [`Transpose`](https://docs.rapidminer.com/latest/studio/operators/blending/table/rotation/transpose.html) (read 2026-09-27)
- VisiData: [`transpose`](https://github.com/saulpw/visidata/blob/7609212ec2febafa9caba7183cbebfaf49627909/visidata/features/transpose.py#L25) (read 2026-09-23)
