Table.Unpivot
TableTransforms specified columns into attribute-value pairs, normalizing a wide table into a tall, narrow format.
Syntax
Table.Unpivot(table as table, pivotColumns as list, attributeColumn as text, valueColumn as text) as tableParameters
| Name | Type | Required | Description |
|---|---|---|---|
table | table | Yes | The input table containing columns to unpivot. |
pivotColumns | list | Yes | A list of column names to unpivot into rows. |
attributeColumn | text | Yes | The name of the new column that holds the original column names. |
valueColumn | text | Yes | The name of the new column that holds the values from the unpivoted columns. |
Return Value
table — A table with the specified columns unpivoted into rows of attribute-value pairs.
Remarks
Table.Unpivot converts selected columns into rows, producing a pair of new columns: one for the original column names (the attribute column) and one for their values (the value column). All columns not listed in pivotColumns are repeated for each unpivoted row.
This is the inverse of Table.Pivot and is useful for normalizing wide datasets where measures are spread across multiple columns into a format suitable for analysis or visualization.
Important: Null values are silently removed during an unpivot operation — any cell that contains null will not produce a row in the output. If you need to preserve the fact that a value was missing, replace nulls with a placeholder (e.g., 0 or "N/A") using Table.ReplaceValue before unpivoting.
Examples
Example 1: Unpivot UnitPrice and Quantity into attribute-value pairs
let
Source = Table.SelectColumns(
Table.FirstN(Sales, 3),
{"Product", "UnitPrice", "Quantity"}
)
in
Table.Unpivot(Source, {"UnitPrice", "Quantity"}, "Measure", "Value")Product | Measure | Value | |
|---|---|---|---|
| 1 | Widget A | UnitPrice | 25 |
| 2 | Widget A | Quantity | 4 |
| 3 | Gadget B | UnitPrice | 50 |
| 4 | Gadget B | Quantity | 2 |
| 5 | Widget C | UnitPrice | 15 |
| 6 | Widget C | Quantity | 10 |