Pivoting Text Data
This page shows how to pivot data whose values are text, so that each record ends up on a row of its own.
Stacked records
Section titled “Stacked records”Data often has to be reshaped before it can be analysed. Here the table on the left must become the table on the right.
In the left-hand table, column A holds the field name and column B the value, and each block of four rows makes up one record. Older systems often export data like this, and the format usually cannot be changed at the source.

Why a plain pivot fails
Section titled “Why a plain pivot fails”Selecting Column 1 in Power Query and clicking Pivot Column, with the default settings, gives this:

Pivot Column produces one row for each distinct combination of the remaining columns. Once Column 1 and Column 2 are used up there are no columns left to tell one record from another, so every value for each field falls into the same cell, and the default aggregation counts them, giving 6 for each field.
Each record is four consecutive rows, so the fix is to give every block of four rows its own ID number. The pivot then has a column that separates one record from the next.
1. Add an index column
Section titled “1. Add an index column”- Click anywhere in the table, then on Excel’s Data tab click From Table/Range.
- In the Power Query editor, go to the Add Column tab, click Index Column, and choose From 0.

2. Integer-divide the index by 4
Section titled “2. Integer-divide the index by 4”- Select the Index column, then on the Transform tab click Standard, and choose Integer-Divide.

- Enter 4, and click OK.

Integer division drops the remainder, so indexes 0 to 3 become 0, indexes 4 to 7 become 1, and so on. Each record’s four rows now share one number:

3. Pivot the data
Section titled “3. Pivot the data”- Select Column 1, then click Pivot Column on the Transform tab.
- Choose Column 2 as the Values Column.
- Under Advanced options, set Aggregate Value Function to Don’t Aggregate.

The data now pivots correctly, with one row per index number:

4. Load the data to Excel
Section titled “4. Load the data to Excel”- Remove the Index column, which is no longer needed.
- Close & Load the query to Excel.
After some formatting, the table has the layout that was wanted:

This example follows Matt Allington’s post Pivoting Text Data Using Power Query on Excelerator BI.