Skip to content

Pivoting data to enable validation

This page shows how to pivot a list into separate columns, so that each column can serve as the source of its own data validation drop-down list elsewhere in the workbook.

The data is a list of employees, each with a role type:

An Excel table headed Source Data with columns Role Type and Employee Name, listing fifteen employees across Role Type 1, 2 and 3

Reshaping it with a query means that, when the source is live data that changes often, a refresh keeps the drop-down lists up to date.

  • Click anywhere in the table, then on Excel’s Data tab click From Table/Range.

The data appears in the Power Query editor like this:

The data in the Power Query editor, with Role Type and Employee Name columns

2. Group the table and number each group’s rows

Section titled “2. Group the table and number each group’s rows”
  • Click the fx button beside the formula bar to add a step, and replace its formula with this:
= Table.Group(Source, {"Role Type"}, {{"Count", (_) => Table.AddIndexColumn(_[[Employee Name]],"idx"), type table}})

The formula groups the table by Role Type. The output column keeps the default name Count, but instead of a count it holds a table for each role. Each table lists the role’s employees, and Table.AddIndexColumn adds an idx column that numbers them from 0.

The grouped query with Role Type and Count columns, and a preview of Role Type 1’s table listing four employees with idx values 0 to 3

  • Click the expand icon on the Count column, and expand all its fields.

The expand menu on the Count column with Employee Name and idx ticked

Each employee is back on a row of their own, now with a number that restarts at 0 for each role:

The expanded query with Role Type, Employee Name and idx columns, where idx runs 0 to 3 for Role Type 1, 0 to 2 for Role Type 2 and 0 to 7 for Role Type 3

  • Select the Role Type column, then click Pivot Column on the Transform tab.
  • Choose Employee Name as the Values Column, and under Advanced options set Aggregate Value Function to Don’t Aggregate.

The Pivot Column dialog using the names in Role Type, with Employee Name as the Values Column and Don’t Aggregate selected

The idx column decides which row each name lands on, so the first employee of every role shares the first row, the second shares the second row, and so on.

  • Remove the idx column, which is no longer needed.

Each role now has a column of its own, ready to be used as a validation list:

The pivoted query with columns Role Type 1, Role Type 2 and Role Type 3, each listing that role’s employees from the top, with null below the shorter lists

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