Lesson 8.3: Combining Queries: Append (Unions) vs Merge (Relational Joins)
Master the two fundamental mechanisms for combining multi-source data inside Power Query: Append Queries (stacking rows vertically like SQL UNION ALL) and Merge Queries (enriching rows horizontally across relational keys like SQL JOIN). Understand all 6 join kindsβincluding Left Anti-joins for forensic auditingβand configure fuzzy matching.
π₯ Video Chapter: Chapter 8 β Power Query & M Language (4:20:30)
π 1. Append vs Merge: Conceptual Comparison
When combining two or more tables in Power Query, analysts must choose between vertical union stacking or horizontal relational enrichment:
View Mermaid Syntax
flowchart TD
subgraph APPEND ["1. APPEND QUERIES (Vertical Row Stacking / SQL UNION ALL)"]
direction TB
A1["Table Q1 (1,000 Rows | 5 Cols)"]
A2["Table Q2 (1,500 Rows | 5 Cols)"]
A1 === A2
A2 ==> A_OUT["Combined Table (2,500 Rows | 5 Cols)\nβ’ Increases Row Count\nβ’ Preserves Column Structure"]
end
subgraph MERGE ["2. MERGE QUERIES (Horizontal Column Joining / SQL JOIN)"]
direction TB
M1["Orders Table\n[OrderID, CustomerID, Total]"]
M2["Customers Table\n[CustomerID, Name, City]"]
M1 -. Relational Match on CustomerID .- M2
M2 ==> M_OUT["Enriched Orders Table\n[OrderID, CustomerID, Total, Name, City]\nβ’ Preserves Row Count\nβ’ Expands Column Width"]
end
style APPEND fill:#e3f2fd,stroke:#1565c0,stroke-width:2px
style MERGE fill:#fff3e0,stroke:#ef6c00,stroke-width:2px
style A_OUT fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px
style M_OUT fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px
| Operational Dimension | Append Queries (Vertical) | Merge Queries (Horizontal) |
|---|---|---|
| SQL Relational Analog | UNION ALL |
INNER JOIN, LEFT JOIN, FULL JOIN |
| Data Flow Direction | Stacks rows top-to-bottom. | Appends columns side-by-side. |
| Prerequisite Condition | Tables share identical or similar column names. | Tables share a common key column (Primary Key / Foreign Key). |
| Primary Use Cases | Combining monthly sales dumps (Jan + Feb + Mar), consolidating multi-branch files. | Enriching orders with customer addresses, matching SKU codes with product catalog prices. |
π₯ 2. Append Queries: Vertical Stacking
Mechanics:
- When you click Home > Append Queries (or Append Queries as New), Power Query maps columns across tables by Exact Name Match (case-sensitive!).
- If Column Name matches exactly, rows stack cleanly into a single column.
- If Column Name differs (e.g.
Clientin Table A vsCustomerin Table B), Power Query creates two separate columns, placing nulls where data is absent.
// Combining two tables via Table.Combine
AppendedResult = Table.Combine({Table_January, Table_February, Table_March})
Enterprise Folder Ingestion (Folder.Files):
Rather than appending 50 branch files manually, analysts use the From Folder connector:
- Data > Get Data > From File > From Folder $\to$ select directory.
- Click Combine & Transform Data.
- Power Query creates a parameterized helper function that extracts, cleans, and auto-appends every CSV or Excel workbook in that folder automatically!
- Whenever a new branch file is dropped into the Windows directory, clicking Refresh All ingests it in seconds.
π 3. Merge Queries: The 6 Relational Join Kinds
Clicking Home > Merge Queries opens the visual join interface. Selecting matching key columns and choosing the Join Kind governs the output:
View Mermaid Syntax
flowchart TD
subgraph JOINS ["The 6 Join Kinds in Power Query"]
J1["<b>Left Outer (Default)</b><br/>All rows from 1st table; matching from 2nd."]
J2["<b>Right Outer</b><br/>All rows from 2nd table; matching from 1st."]
J3["<b>Full Outer</b><br/>All rows from both tables; nulls when unmatched."]
J4["<b>Inner</b><br/>Only rows that match in both tables."]
J5["<b>Left Anti (Audit Tool)</b><br/>Rows in 1st table that have NO match in 2nd."]
J6["<b>Right Anti</b><br/>Rows in 2nd table that have NO match in 1st."]
end
style JOINS fill:#fafafa,stroke:#37474f,stroke-width:2px
style J1 fill:#e3f2fd,stroke:#1565c0,stroke-width:2px
style J4 fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px
style J5 fill:#ffebee,stroke:#c62828,stroke-width:2px
Forensic Auditing with Anti-Joins (Left Anti):
The Left Anti join is an indispensable diagnostic weapon for data analysts:
- Business Problem: Why did 15 customer orders fail to ship?
- Execution: Merge
OrderswithCustomersusing Left Anti. - Result: Instantly isolates all orders that reference non-existent or deleted
CustomerIDvalues, exposing broken referential integrity in seconds!
π 4. Expanding vs Aggregating Merged Tables
When two tables are merged, Power Query inserts a new column containing nested Table objects. Clicking the dual-arrow icon on the column header presents two paths:
View Mermaid Syntax
flowchart LR
MERGED["Merged Column\n[Table Object]"] --> EXP["<b>Expand</b><br/>Extracts specific columns<br/>(e.g., Name, Category, Price)<br/>Duplicates parent rows if 1:N"]
MERGED --> AGG["<b>Aggregate</b><br/>Calculates scalar summaries<br/>(e.g., Count of Orders, Sum of Sales)<br/>Maintains 1:1 row granularity"]
style MERGED fill:#fff8e1,stroke:#f57f17,stroke-width:2px
style EXP fill:#e3f2fd,stroke:#1565c0,stroke-width:2px
style AGG fill:#e8f5e9,stroke:#2e7d32,stroke-width:2px
- Expand (
Table.ExpandTableColumn):- Pulls individual fields into the main table.
- Warning: If merging a 1-to-many relationship (e.g. Customers merged with Orders), expanding Order items will duplicate customer rows!
- Aggregate (
Table.AggregateTableColumn):- Computes aggregations directly inside the join (e.g.
Count of Orders,Sum of TotalRevenue,Average of Rating) without creating Cartesian row explosions.
- Computes aggregations directly inside the join (e.g.
ποΈ 5. Fuzzy Matching in Merge Queries
Transactional records frequently suffer from typos, casing variations, and minor discrepancies (e.g. Microsoft Corporation vs Microsoft Corp):
- Checking Use fuzzy matching to perform the merge activates text distance algorithms (Jaccard similarity).
- Similarity Threshold: Specify tolerance between
0.00(matches everything) and1.00(exact match only). Default is0.80. - Ignore Case & Spaces: Automatically bridges casing anomalies.
- Transformation Table: Connect an explicit mapping dictionary mapping abbreviations to standardized names.
Related Knowledge
- Notes:
- Concepts: Power Query, ETL Process, M Language, Dimensional Modeling
- Course Reference & Workbooks:
- Module 7 Dataset Documentation
- Module 8 Dataset Documentation
- Laboratory 1:
Module_7_Demo.xlsx - Laboratory 2:
Module_8_Demo.xlsx