OpenBI Docs Buy

Table.Unpivot

Turns the columns you name into rows of two columns: the old column's name and its value.

Group: Table. Power Query M has it too: a query that uses it is written as in Power BI.

Syntax

Table.Unpivot(table as table, pivotColumns as list, attributeColumn as text, valueColumn as text) as table
ParameterTypeDescription
tabletableThe table in wide form.
pivotColumnslistThe columns to turn into rows.
attributeColumntextThe name of the new column for the old column names.
valueColumntextThe name of the new column for their values.

Returns

table. The columns you didn't name, then the two new ones: a row per old row and named column.

Remarks

  • A null cell gives no row.
  • When columns can be added in the source (a new month), name the columns to keep with Table.UnpivotOtherColumns instead: Unpivot Other Columns in Transform data writes that.

Examples

Months into rows

Table.Unpivot(#table({"Shop", "Jan", "Feb"}, {{"Oslo", 10, 12}, {"Bergen", 7, null}}), {"Jan", "Feb"}, "Month", "Sales")
ShopMonthSales
OsloJan10
OsloFeb12
BergenJan7

Bergen has no February value, so it has no February row.

Table.UnpivotOtherColumns, Table.Pivot, Table.Transpose.

Last updated · OpenBI Studio 0.3.79