Skip to content

Turn a wide report into a list with Unpivot, then total it with Group By

Power Query basics9 minPremium

Builds on Load data into Power Query and set column types.

A finance analyst in Vienna gets each department's budget as a wide sheet: one row per cost center and one column per month. Her PivotTable needs a list instead, one row per cost center and month, and the CFO wants the total for each month.

How it works

A report with a column per month is easy to read and hard to analyze, since each month is a heading of its own. Unpivot turns those headings into values in one column.

  1. Select the columns that name each row, such as Cost center.
  2. Choose Transform > Unpivot Columns > Unpivot Other Columns. Every other column turns into rows: a column called Attribute holds the old heading, the month, and a column called Value holds the number that was under it. An empty cell makes no row.
  3. Double-click Attribute and Value to rename them, such as Month and Amount.

Unpivot Other Columns names the columns you keep, so when April's column arrives, the next refresh unpivots it too. Unpivot Only Selected Columns names the months, and a new month stays out.

Group By, on the Home tab, makes one row per value of a column and adds a column worked out from each group's rows: Sum, Average, Median, Min, Max, Count Rows or Count Distinct Rows. Pick the column to group by, name the new column, and choose the operation and the column it works on. Advanced adds more columns to group by, or more new columns, such as a total and a count side by side. The summary is a step like any other, so every refresh works it out again.

Example

Two cost centers of the budget, before and after Unpivot Other Columns and the renames:

Each month's heading becomes a value in Month, and the number under it moves to Amount. Facilities' empty February makes no row.

Common mistakes

  • Leaving Attribute and Value as they are. A PivotTable then shows fields called Attribute and Value. Rename them.
  • Group By on the wrong column, such as Cost center when the question is per month. Group by the column whose values should become the rows.
  • Count Rows when the question is a total. It counts the rows in each group. Choose Sum, and the column to add up.

In short

  • Unpivot Other Columns turns month columns into rows and keeps working when new months arrive.
  • Rename Attribute and Value to say what they hold.
  • Group By totals, averages or counts a list per group, as a step that each refresh repeats.

Practice

Premium

4 exercises: 3 queries and 1 quiz question.

Practice is part of Premium

Every lesson is free to read, and you can practice the free lessons without an account. This lesson's exercises are part of Premium, which you add to a free account.