Unpivot
Reshape wide tables into long format. Selected columns are melted into two new columns: one holding the original column name, one holding its value. Each input row produces one output row per unpivoted column. Use it to convert spreadsheet-style monthly columns into a single date column, or to feed wide pivot tables into transforms that expect tidy data.
How it works
Section titled “How it works”Unpivot is a full-dataset batch transform: it buffers the entire input before producing output, because it needs the row shape to determine which columns are index columns (everything not unpivoted) versus value columns (the ones being melted).
For an input row with N unpivoted columns, the transform emits N output rows. Each output row carries:
- All non-unpivoted columns from the source row, unchanged (the “index” columns)
- The variable column, set to the name of one of the unpivoted columns
- The value column, set to the cell value at that column (or
nullif missing)
The order of output rows is: input row 1’s first unpivoted column, then input row 1’s second, …, then input row 2’s first, and so on. The order of variables within a group follows the order of columnsToUnpivot in the configuration, not the column order of the source.
If columnsToUnpivot is empty, rows pass through unchanged.
Input: One tabular data connection. Output: A long-format table with all index columns plus the variable and value columns.
Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
columnsToUnpivot | string[] | [] | Names of columns to melt. Empty list is a passthrough. |
variableColumnName | string | "variable" | Name of the output column that holds the original column name. Required. |
valueColumnName | string | "value" | Name of the output column that holds the cell value. Required. |
Examples
Section titled “Examples”Melt monthly columns into a long format
Section titled “Melt monthly columns into a long format”You have quarterly sales as wide columns (q1, q2, q3, q4) and want them as one quarter / sales pair per row.
Before:
| customer | q1 | q2 | q3 | q4 |
|---|---|---|---|---|
| Acme Corp | 1200 | 1500 | 1800 | 2100 |
| Beta Inc | 800 | 900 | 1100 | 1300 |
Configuration: columns to unpivot: ["q1", "q2", "q3", "q4"], variable column: quarter, value column: sales.
After:
| customer | quarter | sales |
|---|---|---|
| Acme Corp | q1 | 1200 |
| Acme Corp | q2 | 1500 |
| Acme Corp | q3 | 1800 |
| Acme Corp | q4 | 2100 |
| Beta Inc | q1 | 800 |
| Beta Inc | q2 | 900 |
| Beta Inc | q3 | 1100 |
| Beta Inc | q4 | 1300 |
Multiple index columns are preserved per output row
Section titled “Multiple index columns are preserved per output row”You want to melt scores while keeping both student and class as identifiers.
Before:
| student | class | math | english | science |
|---|---|---|---|---|
| Alice | 5A | 92 | 88 | 95 |
| Bob | 5B | 78 | 84 | 80 |
Configuration: columns to unpivot: ["math", "english", "science"], variable column: subject, value column: score.
After:
| student | class | subject | score |
|---|---|---|---|
| Alice | 5A | math | 92 |
| Alice | 5A | english | 88 |
| Alice | 5A | science | 95 |
| Bob | 5B | math | 78 |
| Bob | 5B | english | 84 |
| Bob | 5B | science | 80 |
Tips and Edge Cases
Section titled “Tips and Edge Cases”- Index columns are inferred from the first row, not from the schema. The transform takes
Object.keys(rows[0])and treats every key not incolumnsToUnpivotas an index column. If row 1 is missing a key that later rows have, that key is dropped from the output. To avoid surprises on ragged inputs, run Stack Rows in union mode upstream so every row has the same shape. Seeapps/web/src/transforms/unpivot/logic.ts:72-74. - Missing values become
null, not empty string. When an unpivoted column is absent from a row (or its value isundefined), the outputvaluecell isnull. Empty string in the source is preserved as"". Seeapps/web/src/transforms/unpivot/logic.ts:84. - One input row produces N output rows in a deterministic order. The output groups together one input row’s unpivoted columns before moving on to the next input row. Sort downstream if you need a different order — Unpivot does not interleave rows by variable.
Related Transforms
Section titled “Related Transforms”- Pivot — the inverse: roll long-format data back into wide columns.
- Group By — aggregate the unpivoted long format (e.g. sum sales per quarter across all customers).
- Filter Rows — drop specific variables (e.g. keep only
q4rows) after unpivoting.