Business Intelligence with Power BI

L03 · Power Query II: Combine

Power Query II: Combine

Learning objectives. By the end of this lesson you will be able to:
  • Append same-shaped files into one table, and explain when appending is the right verb
  • Merge tables on a key column, and choose the join kind on purpose
  • Predict how each join kind changes a row count — before running it
  • Use anti joins as a data-quality instrument
  • Unpivot a crosstab into analysis-ready tall data

Estimated time: 60–75 minutes of reading and follow-along, before practice.

Why this matters

Real data does not arrive in one file. It arrives as this month's file, next to last month's file, next to a lookup list somebody maintains in a spreadsheet, next to a budget grid formatted for reading rather than analysis. This week's inbox contains all three shapes at once: six monthly sales exports (January through June 2026, one file each), the customer list you cleaned last lesson, and finance's budget crosstab — regions and categories down the side, twelve months marching across the columns.

Combining tables has two fundamentally different verbs, and confusing them is one of the oldest mistakes in data work. Append stacks — same-shaped tables, one on top of another, more rows. Merge looks up — different-shaped tables joined by a shared key, more columns. Six monthly files of identical shape? Append. Sales lines that need customer segments attached? Merge. Get them backwards and Power Query will not stop you; it will do exactly the wrong thing you asked for, fluently.

Append: the stack

Load all six monthly exports (each via Get data, or — the professional move once you have seen it — the Folder connector, which ingests every file in a directory in one step and is how this becomes twelve files next year without you touching anything). Each file has the same nine columns; January holds 3,903 rows, and the months grow from there.

Then: Home → Append Queries → Append Queries as New, select all six. One table: 26,139 rows, January through June, ready for a single line chart instead of six. A quick sanity check — build a temporary revenue total against it — gives $11,515,008.14, which reconciles with the company's H1 figure to the cent-level rounding difference you would expect. Verified, stacked, done.

[Screenshot l03-append-dialog — Append Queries as New dialog with the six monthly queries selected; result showing 26,139 rows]
Append: same shape, stacked. Six files become one table of 26,139 rows.
What append demands Matching columns, by name. A file whose column got renamed — Qty instead of Quantity — appends anyway: the mismatched column arrives as a separate, mostly-null column, and nothing warns you. After every append, check the result's column list and its null bars. Thirty seconds; the profile pane again.

Merge: the lookup

The appended sales table has a CustomerID column but no segments, no cities — those live in the customer table from Lesson 2. Home → Merge Queries: pick the sales table, pick the customer table, click the key column in each. Now the dialog asks the question this entire lesson exists to make you take seriously: Join Kind.

The experiment that settles it

Here is the situation, with real counts. The sales table has 26,139 rows. The marketing export you cleaned holds only 500 customers — a sample, not the full customer base. Merging on CustomerID:

Join kindResult rowsWhat it means
Left Outer (default)26,139Every sale kept; customer details attached where they exist, null where they don't
Inner1,627Only sales whose customer is in the 500-person list. 24,512 rows silently gone
Left Anti24,512Only the sales with no match — the complement of Inner

Read the Inner row again. Choosing Inner instead of the default did not error, did not warn — it produced a smaller, plausible-looking table missing 94% of the company's sales. A revenue chart built on it would look completely professional and be catastrophically wrong. The join kind is not a technicality; it is a claim about which rows deserve to exist, and the row count afterward is how you audit the claim you made.

[Screenshot l03-merge-dialog — Merge dialog, CustomerID selected in both tables, join-kind dropdown open showing all six kinds]
The Merge dialog. The dropdown at the bottom is the whole lesson.
The habit Write down the row count you expect before clicking OK, then compare. Left join: same as the left table (26,139 — unless the right table has duplicate keys, which multiplies matching rows instead; profile your key first). Inner: at most the smaller side's reach. If the result surprises you, the join is telling you something about your data — listen before shipping.

After a merge, the joined table arrives folded into a single column; click its expand icon to choose which of the customer columns to bring through (Segment and City, say — not all eleven). Every column you expand is a column every future refresh carries; take what the analysis needs.

If you know SQL — and if you don't

Students who have met SQL will recognize this whole section: Merge is JOIN, Append is UNION, and the join kinds are the same animals wearing friendlier names. If you have never touched SQL, you have just learned the concept that half of SQL interviews revolve around, with a dialog box instead of a keyword — the idea transfers whenever you get there.

Anti joins: the auditor's join

That Left Anti count — 24,512 sales with no matching customer — looked like a failure above. Flip the question and it becomes an instrument. "Which sales reference a customer missing from our marketing list?" is exactly the question an auditor, or a data-quality check, wants answered — and Left Anti answers it in one step. Keep this pattern: anti joins find orphans. Orders without valid products, employees without departments, payments without invoices. Any time two tables are supposed to agree, the anti join measures precisely how much they don't.

Unpivot: the crosstab comes in from the cold

Finance's budget_crosstab_2026.csv is formatted the way humans like to read: 30 rows — one per region-and-category pair — with twelve month columns marching across. Beautiful on paper. Useless for analysis: you cannot put "all twelve month columns" on a chart axis, filter to Q2, or join months against actuals, because the month is trapped in the column headers instead of living in the data.

The cure: select the two identity columns (Region, Category), then Transform → Unpivot Other Columns. The twelve month columns collapse into two: Attribute (the month, freed from the headers) and Value (the target). Rename them properly, set the types, and the grid becomes 360 tall rows — 30 × 12, verified — each one saying Region, Category, Month, Target. That shape joins, filters, and charts like every other table you own.

[Screenshot l03-unpivot — before/after: the 30×12 crosstab and the 360-row tall result with Attribute/Value renamed to Month/Target]
Unpivot: the month escapes the column headers. 30 wide rows become 360 tall ones.
Wide or tall? Neither shape is wrong; they serve different masters. Wide crosstabs are for human eyes — finance should keep making them. Tall data is for analysis. The skill is recognizing which one you are holding and converting without complaint. ("Unpivot Other Columns," rather than selecting the twelve month columns directly, is the professional's choice for a reason: when finance adds a thirteenth month column in January, "other columns" catches it automatically.)
Knowledge check. Twelve regional offices each send a weekly sales file with identical columns. Head office wants one table covering all offices. Which operation, and why?
Knowledge check. You merge 26,139 sales rows against a 500-customer list expecting an enriched sales table, but the result has 1,627 rows. What almost certainly happened?
Knowledge check. Compliance asks: "which invoices reference a vendor that is NOT in the approved-vendor table?" Which join kind answers in one step?

Common mistakes

  • Merging when you meant appending (or the reverse). More rows wanted → append. More columns wanted → merge. Say the sentence before opening the dialog.
  • Accepting the default join kind without deciding. Left Outer is a fine default precisely because it deletes nothing — but "I didn't choose" is not the same as "I chose Left Outer." The row count afterward is your signature on the decision.
  • Merging on a key with duplicates on the right side. Each duplicate multiplies the matching left rows — the join that quietly grows your table. Profile the key column's distinct count first (500 rows, 500 distinct = safe).
  • Expanding every column after a merge. Take Segment and City, not all eleven. Width is a cost every refresh pays.
  • Unpivoting by selecting the month columns instead of "Unpivot Other Columns." Works today; breaks in January when a new month column arrives and isn't in the selection. Other-columns is change-proof in the direction data actually changes.

Summary

  • Append stacks, merge looks up. Same shape/more rows versus shared key/more columns — six files became 26,139 rows; a 500-customer list became two new columns.
  • The join kind is a claim about which rows deserve to exist. Left Outer kept 26,139; Inner silently kept 1,627. Predict the count, then verify it.
  • Anti joins find orphans — 24,512 sales outside the marketing list, one step, and the same pattern audits any two tables that are supposed to agree.
  • Unpivot frees data from column headers — the 30×12 crosstab became 360 analysis-ready rows, and "Unpivot Other Columns" survives next year's new column.
  • All of it is recorded recipe — next month's files inherit every decision automatically.