Pivot, Unpivot Columns & Handling Missing Values
Overview & Learning Objectives
Combining multiple data tables into a unified model is a cornerstone of analytics. In Power Query, you combine tables in two ways: Merging (combining columns horizontally using relational keys, like an SQL JOIN) and Appending (stacking rows vertically on matching column schemas, like an SQL UNION ALL).
- Contrast Merge Queries (horizontal join) with Append Queries (vertical union).
- Execute Left Outer, Inner, Full Outer, and Anti Joins inside Power Query.
- Append monthly or annual transaction batches into a single consolidated Fact table.
Industry Standard
Standard: Analytics teams at Flipkart and Swiggy mandate appending monthly sales partitions into a single consolidated Fact table while keeping dimensions normalized to avoid wide de-normalized table sprawl.
Real-World Example: Burger Point Quick Service Chain
Burger Point has two separate monthly sales files (January_Orders.csv and February_Orders.csv), plus a Store_Master table with manager names.
| Operation | Inputs | Mechanism | Resulting Schema |
|---|---|---|---|
| Append Queries | Jan (5,000 rows) + Feb (6,000 rows) | Vertical Stack | 11,000 rows, same 6 columns |
| Merge Queries | Orders Table + Store_Master | Horizontal Join on StoreID | 11,000 rows, 8 columns (+Manager, +Region) |
Syntax & Core Workflow
Home Tab -> Combine Group -> Merge Queries (or Append Queries) -> Select Matching Keys -> Choose Join Kind
Parameters Breakdown
Append Queries: Stacks rows from two or more tables vertically into a single longer table with identical columns.Merge Queries: Joins two tables side-by-side horizontally based on matching primary/foreign key values.Left Outer Join: Retains all rows from the first table and matches available rows from the second table.Left Anti Join: Retains only rows from the first table that do NOT have a matching key in the second table.
Sample Walkthrough (Q&A)
Question: Which join kind should you use in Merge Queries to find all registered customers who have never made a purchase?
Formula / Action: Merge Customers with Orders on CustomerID -> Select "Left Anti" join kind.
Result: Outputs only customers who have 0 matching records in Orders.
Explanation: Left Anti identifies orphan keys in the primary table. It is the fastest way to audit unengaged users or missing reference data.
Common Mistakes & Limitations
- Merging large tables inside Power Query when creating a relationship in the Data Model would be far faster and consume 10x less memory.
- Appending tables where column headers have subtle spelling or case differences (e.g. "Revenue" vs "revenue"), which creates separate fragmented columns.
Keyboard Shortcuts
| Action | Windows | Mac |
|---|---|---|
| Open Merge Queries window | Alt -> H -> M -> Q | Option -> H -> M -> Q |
| Open Append Queries window | Alt -> H -> A -> Q | Option -> H -> A -> Q |
Pro Tips & Modern Alternatives
- Instead of merging dimensions into the fact table in Power Query, load them as separate tables and link them in the Model View using standard 1-to-Many relationships.
- Use "Append Queries as New" to preserve your original source staging queries unchanged for auditing.