Table.Pivot
TableRotates distinct values from an attribute column into new column headers, aggregating corresponding values.
Syntax
Table.Pivot(table as table, pivotValues as list, attributeColumn as text, valueColumn as text, optional aggregationFunction as nullable function) as tableParameters
| Name | Type | Required | Description |
|---|---|---|---|
table | table | Yes | The input table to pivot. |
pivotValues | list | Yes | A list of values from the attribute column that become new column headers. |
attributeColumn | text | Yes | The column whose distinct values are pivoted into column headers. |
valueColumn | text | Yes | The column whose values populate the new pivoted columns. |
aggregationFunction | function | No | An optional aggregation function applied when multiple values exist for a pivot combination (e.g., List.Sum). |
Return Value
table — A table with distinct values from the attribute column transformed into column headers, with aggregated values from the value column.
Remarks
Table.Pivot transforms a tall, narrow table into a wide table by turning distinct values from the attributeColumn into new columns. The pivotValues list specifies which values become column headers, and the valueColumn provides the data that fills the new columns.
When multiple rows map to the same pivot combination, you must supply an aggregationFunction (such as List.Sum or List.Count) to resolve the conflict. Without an aggregation function, duplicate combinations cause an error.
Examples
Example 1: Pivot Category into columns with Quantity values
let
Source = Table.SelectColumns(Sales, {"Region", "Category", "Quantity"})
in
Table.Pivot(Source, {"Widgets", "Gadgets", "Misc"}, "Category", "Quantity", List.Sum)Result
Region | Widgets | Gadgets | Misc | |
|---|---|---|---|---|
| 1 | East | 14 | null | 1 |
| 2 | West | 6 | 5 | null |
| 3 | North | 8 | 1 | null |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks