Group pivot and unpivot
Move from a spreadsheet layout to a fact table
Wide budgets have one column per month. A long budget fact has one observation per business key and month. Unpivot converts selected headers to attribute values; pivot performs the reverse shape change when the key and attribute identify a cell. Grouping deliberately reduces grain. These operations are different from transposing the entire grid. All examples are standalone blank-query expressions for Power Query M in a disposable Power BI Desktop file. No external source or account is needed. Results are predicted, not native execution evidence; exact Desktop build NOT RUN.
Unpivot a complete budget and reconcile totals
let Wide = #table(type table [Region = text, Jan = number, Feb = number], {{"North", 120, 80}, {"South", 60, 40}}), Long = Table.Unpivot(Wide, {"Jan", "Feb"}, "Month", "BudgetUSD"), Typed = Table.TransformColumnTypes(Long, {{"BudgetUSD", Currency.Type}}, "en-US"), Totals = Table.Group(Typed, {"Region"}, {{"TotalUSD", each List.Sum([BudgetUSD]), Currency.Type}})in [Fact = Typed, RegionalTotals = Totals]Expected fact rows as an unordered set: North Jan 120, North Feb 80, South Jan 60, South Feb 40. Regional totals: North 200, South 100; grand total 300 USD. Group returns no guaranteed row order; sort explicitly if order matters. Here Jan/Feb refer only to 2026; a real fact needs a year-month key. Table.Unpivot omits null-valued cells: if South Feb were null, the result would have three rows, not four; missing is not zero. The lab audits completeness before unpivot.
Resolve pivot collisions only with a valid aggregation
let Lines = #table(type table [Region = text, Month = text, BudgetUSD = number], {{"North", "Jan", 70}, {"North", "Jan", 50}, {"North", "Feb", 80}, {"South", "Jan", 60}}), Wide = Table.Pivot(Lines, {"Jan", "Feb"}, "Month", "BudgetUSD", List.Sum), Grid = Table.Transpose(#table({"A", "B"}, {{"x", "y"}, {"z", "w"}}))in [Wide = Wide, Transposed = Grid]Expected Wide: North Jan 120 Feb 80; South Jan 60 Feb null. Aggregation is valid only if both North January rows are approved additive allocations, not duplicate copies of one allocation. Without a suitable aggregation, multiple values for a target cell can fail. The transposed grid has rows x/z and y/w; original column names are not preserved as ordinary data by this operation. Transpose is not a substitute for a keyed unpivot.
Manage month schema and missing cells
Use an explicit list of approved month columns in a fixed contract. Automatically unpivoting every other column can accidentally treat a new Notes field as a month. Conversely a new month can remain outside an explicit list unless schema drift is monitored. Check expected and actual headers, unique source keys, null/error cells, row counts and known-value subtotals. Do not declare totals preserved if unknown budget values prevent a full reconciliation. Use dates or sortable year-month fields rather than alphabetic month labels in final reporting.
Practice: audit a changed budget
In the complete wide fixture, set South Feb to zero, then to null in a separate variation. Predict output row count and known total in each case. Explain why only the zero case describes a confirmed zero budget. Complete the budget normalization lab for a reject-table strategy.