Day 3 — Shaping data — split, group, append and merge
Four operations that cover most of the reshaping you will ever need.
Split Column
One column holding several facts is the most common shape problem in exported data. A code like DL-2024-0912 is really a state, a year and a serial number.
Split by each occurrence and you get three columns. Split at the left-most delimiter and you get two — the state, and everything else. Which you want depends on whether the tail is meaningful.
Group By
Group By collapses rows. If the source has one row per line item but the report only ever shows order totals, group in Power Query and load a tenth of the rows.
Append — stacking tables
Twelve monthly files with identical columns. Append puts them end to end into one table.
Better still, point Power Query at the folder rather than the files. Then next month you drop the new file in and refresh — no edit needed.
Merge — joining tables
Merge is Power Query’s join. It brings columns from one table into another, matching on a key.
| Join kind | Keeps |
|---|---|
| Left Outer | Everything from the first table — the safe default |
| Inner | Only rows that match both sides |
| Left Anti | Only rows with no match — how you find orphans |
But should you merge at all?
This is the important question of the day. You could merge Product and Region into Sales and end up with one wide flat table. Many people do, because it feels like the Excel they know.
Where the model stands
Sales stayed narrow, the descriptive columns stayed in their own tables:
Six products exist and all six have been sold. If the distinct count came back lower, some product in the catalogue has never sold — which is a genuine business answer, not a data error.
Try these yourself
- Describe how you would split "DL-2024-0912" into state, year and serial.
- Explain when Group By is the wrong choice.
- You have 12 monthly files. Say which is better — Append or a folder source — and why.
- Explain what a Left Anti join tells you about your data.
- Give one reason to build a relationship instead of merging.
