Power Query Intermediate Lesson 7: Two Header Rows – Unpivot a Region-over-Month Report

Power Query Intermediate Lesson 7: Two Header Rows - Unpivot a Region-over-Month Report 1

📎 This article includes 3 downloadable practice files ↓

⏱ 2 min read

📘 Power Query Intermediate Course · Lesson 7 of 8

Advertisement

Reports from other people often look like this: regions as merged cells on row 1, months on row 2, products down the side. Perfect for reading, useless for pivots.

North        South
Product    Jul   Aug    Jul   Aug
Notebook   120   140    90    95

The recipe

  1. Transpose so the two header rows become two columns.
  2. Replace blanks with null and Fill Down the region column (merged cells export as one value then blanks).
  3. Merge the two columns with a separator: North|Jul.
  4. Transpose back and Use First Row as Headers.
  5. Unpivot Other Columns (select Product first).
  6. Split the attribute column by “|” into Region and Month.
Header = Table.CombineColumns(FilledRegion, {"Column1", "Column2"},
            each Text.Combine(List.RemoveNulls(_), "|"), "Key"),
Unpivoted = Table.UnpivotOtherColumns(Back, {"Product"}, "Key", "Qty"),
Split = Table.SplitColumn(Unpivoted, "Key", Splitter.SplitTextByDelimiter("|"), {"Region", "Month"})

Result: 12 tidy rows (3 products × 2 regions × 2 months), ready for any PivotTable.

💡 Use Unpivot Other Columns, not Unpivot Columns: when next month’s file adds “Sep”, it’s picked up automatically.

Practice

Unzip the source files (e.g. to D:\PQ\). Try to build the query with the ribbon first, then compare with the M solution and the expected result. Every solution was run by Excel’s own Power Query engine before publishing.

📎 Practice files for this article

⬇ Download all 3 files (ZIP · 8 KB)

  • 🗂️
    Practice source files (zip)All messy CSVs for the course: invoices, payments, typed customer names, credit history, contacts, branch files, a two-row-header report and an ERP register.
    ⬇ ZIP · 3 KB
  • 📄
    Lesson 7 M solutionThe full query. Paste into Advanced Editor and change the Folder line.
    ⬇ PQ · 1 KB
  • 📗
    Expected resultWhat the query returned when Excel ran it, to compare with yours.
    ⬇ XLSX · 5 KB

Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.

Advertisement
✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free · AI can be wrong

Leave a Reply

Your email address will not be published. Required fields are marked *