Skip to content

Pivoting on multiple measures

This page shows how to pivot data that has more than one measure, so that every product has a column for each measure.

The data below has one row per sale, with the date, the product, and two measures, Amount and Unit:

An Excel table with columns Date, Product, Amount and Unit, where the products are Bike and Car

The aim is to show the amount and the units side by side for each date, separately for bikes and for cars, which means four measure columns: bike amount, bike units, car amount and car units. Pivot Column on its own pivots only one values column, so the two measures first have to be brought into one column.

In the Power Query editor, the data looks like this:

The data in the Power Query editor, with Date as a date and time, Product as text, and Amount and Unit as whole numbers

  • Select the Amount and Unit columns.
  • Right-click, and choose Unpivot Columns.

The right-click menu on the selected Amount and Unit columns, with Unpivot Columns highlighted

Each sale now takes two rows, one for each measure, with the measure’s name in Attribute and its figure in Value:

The unpivoted query with columns Date, Product, Attribute and Value, where each sale has an Amount row and a Unit row

  • Select the Product and Attribute columns, right-click, and choose Merge Columns.

The right-click menu on the selected Product and Attribute columns, with Merge Columns highlighted

  • Choose –Custom– as the separator, and enter a full stop.

The Merge Columns dialog with a custom separator of a full stop and the new column named Merged

The new Merged column combines the two names, such as Bike.Amount and Car.Unit:

The query with columns Date, Merged and Value, where Merged holds values such as Bike.Amount and Bike.Unit

  • Select the Merged column, then click Pivot Column on the Transform tab.
  • Choose Value as the Values Column, and keep Sum as the Aggregate Value Function.

The Pivot Column dialog using the names in Merged, with Value as the Values Column and Sum as the aggregate function

  • Change the Date column’s data type to Date.

The data now has one row per date, with a column for each product and measure:

The pivoted query with columns Date, Bike.Amount, Bike.Unit, Car.Amount and Car.Unit, where dates with no sale of a product show null

  • Click Close & Load to load the result to Excel.