Locked lesson.
About this lesson
This lesson exposes a very important pattern for wrangling data. Once you can get it into a single column, hit it with this recipe and it will land nicely into a table.
Exercise files
Download this lesson’s related exercise files. You can download source data files for the course from the resources section of your Lessons page.
Pivoting Stacked Data.xlsx19.5 KB Pivoting Stacked Data - Completed.xlsx
25.9 KB
Quick reference
Pivoting Stacked Data
An overview of pivoting data that is stacked in one column.
When to use
When you have a column that has data stacked in a consistent repeating pattern of x rows per transaction and need to transpose each block and stack them into a tabular format.
Instructions
Getting started
- Create a new query to bring your data to Power Query
- If a header row exists in the data, promote it to be the header row
Creating the transaction ID column
- Add Column --> Index Column --> From 0 (zero)
- Highlight Index column --> Add Column --> Standard --> Integer-Divide
- Enter the “magic” number (the number in the index column that corresponds with the first line of the second instance of the row pattern) --> OK
Creating the transaction line ID column
- Highlight Index column --> Transform --> Standard --> Modulo
Pivoting the data
- Select the Index column --> Transform --> Pivot Column
- Select the column to preserve in the body area of the pivoted date (the values you want to see)
- Select Advanced Options --> Don’t Aggregate --> OK
- The data should not be in an unpivoted format
Finishing the query
- Remove the Integer-Divide (Transaction ID) column
- Apply any other transformations as required
- Set data type for each column
- Rename the query
- Close & Load the query
Hints & tips
- Remember, the “magic” number is the first line of the second transaction
- The Integer-Divide function calculates the number of times the “magic” number can be extracted from the value in the Index column
Lesson notes are only available for subscribers.