Power Query course · Lesson 10 of 17
Merge queries: every join kind explained
Join two queries on matching keys with Merge Queries: Left, Right, Full Outer, Inner, Left Anti and Right Anti, multi-column keys and fuzzy matching.
Merge brings columns from one query into another wherever a key matches, like XLOOKUP or VLOOKUP but for whole tables at once. It is how you add customer countries to orders, product categories to sales lines, cost centres to HR records, or find which invoices are missing from the bank statement. Databases call this a join, and Power Query offers six kinds. This lesson shows each one on the same two small tables, so you can see exactly which rows survive.
| A | B | C | |
|---|---|---|---|
| 1 | Order | Cust ID | Amount |
| 2 | SO-801 | C01 | 1200 |
| 3 | SO-802 | C02 | 450 |
| 4 | SO-803 | C05 | 980 |
| 5 | SO-804 | C01 | 2300 |
Before, left table 'Orders'. C05 does not exist in Customers.
| A | B | C | |
|---|---|---|---|
| 1 | Cust ID | Customer | Country |
| 2 | C01 | Nordic Foods | Norway |
| 3 | C02 | Agora Market | Greece |
| 4 | C03 | Baltic Trade | Latvia |
Before, right table 'Customers'. C03 has no orders.
How to merge
- Open the
Ordersquery in the editor. - Choose Home › Combine › Merge Queries › Merge Queries as New (or Merge Queries to add the step to
Ordersitself). - In the top half,
Ordersis already selected. Click theCust IDheader to mark it as the key. - In the drop-down below, choose
Customersand click itsCust IDheader. - Choose the Join Kind (default Left Outer).
- Read the message at the bottom, for example The selection matches 3 of 4 rows from the first table. It is your first quality check.
- Click OK. A new column named
Customersappears, with the wordTablein each cell. - Click the expand icon in the
Customersheader, tick the columns you want (hereCountry), untick Use original column name as prefix, and click OK.
let
Source = Table.NestedJoin(Orders, {"Cust ID"}, Customers, {"Cust ID"}, "Customers", JoinKind.LeftOuter),
Expanded = Table.ExpandTableColumn(Source, "Customers", {"Country"}, {"Country"})
in
ExpandedThe six join kinds
Left Outer: all from the first, matching from the second
The everyday lookup. Every order is kept; customers' data is added where a match exists, null where it does not. If you are coming from VLOOKUP, this is the one you want.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Order | Cust ID | Amount | Country |
| 2 | SO-801 | C01 | 1200 | Norway |
| 3 | SO-802 | C02 | 450 | Greece |
| 4 | SO-803 | C05 | 980 | null |
| 5 | SO-804 | C01 | 2300 | Norway |
After, Left Outer: 4 rows. SO-803 gets null because C05 is unknown.
Right Outer: all from the second, matching from the first
The mirror image: every customer is kept, with their orders where they exist. A customer with two orders appears twice; a customer without orders appears once with nulls in the order columns. To see the customer ID for that row you must expand it from the nested table, because the left key column is null there.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Order | Cust ID | Amount | Customers.Cust ID | Country |
| 2 | SO-801 | C01 | 1200 | C01 | Norway |
| 3 | SO-804 | C01 | 2300 | C01 | Norway |
| 4 | SO-802 | C02 | 450 | C02 | Greece |
| 5 | null | null | null | C03 | Latvia |
After, Right Outer, with Cust ID and Country expanded (prefix kept, then Customers.Country renamed to Country): 4 rows. SO-803 is gone; C03 appears without an order.
Full Outer: everything from both
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Order | Cust ID | Amount | Customers.Cust ID | Country |
| 2 | SO-801 | C01 | 1200 | C01 | Norway |
| 3 | SO-802 | C02 | 450 | C02 | Greece |
| 4 | SO-803 | C05 | 980 | null | null |
| 5 | SO-804 | C01 | 2300 | C01 | Norway |
| 6 | null | null | null | C03 | Latvia |
After, Full Outer, expanded the same way: 5 rows. Matches are combined; unmatched rows from either side are kept with nulls.
Full Outer is the tool for reconciliations: list the invoices from the accounting system and the payments from the bank in one table, then filter where either side is null.
Inner: only rows that match
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Order | Cust ID | Amount | Country |
| 2 | SO-801 | C01 | 1200 | Norway |
| 3 | SO-802 | C02 | 450 | Greece |
| 4 | SO-804 | C01 | 2300 | Norway |
After, Inner: 3 rows. Unmatched rows from both sides are dropped.
Left Anti: rows in the first with no match
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Order | Cust ID | Amount | Customers |
| 2 | SO-803 | C05 | 980 | Table |
After, Left Anti: only SO-803. The nested Customers table is empty; you can remove that column.
Left Anti is an exception report: orders with unknown customers, employees missing from payroll, invoices not yet paid. Run it before a Left Outer merge to make sure the master list is complete.
Right Anti: rows in the second with no match
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Order | Cust ID | Amount | Customers.Cust ID | Customers.Customer |
| 2 | null | null | null | C03 | Baltic Trade |
After, Right Anti (expanded): only C03, the customer with no orders this period.
Useful for 'who did not buy this month?' or 'which products never sold?'.
| Join kind | Rows from Orders | Rows from Customers | Rows in the example |
|---|---|---|---|
| Left Outer | All | Matching | 4 |
| Right Outer | Matching | All | 4 |
| Full Outer | All | All | 5 |
| Inner | Matching | Matching | 3 |
| Left Anti | Non-matching only | None | 1 |
| Right Anti | None | Non-matching only | 1 |
Duplicates in the lookup table multiply rows
A merge returns every matching row. If Customers accidentally contains C01 twice (say, an old and a new address), each C01 order becomes two rows after expanding, and your revenue total doubles for that customer. A VLOOKUP would have returned the first match only.
Cust ID in Customers and look at View › Column distribution; distinct and unique counts should equal the row count. Or apply Remove Rows › Remove Duplicates on the key in the lookup query.When keys do not match
- Types: the key columns must have the same type. A number 1001 does not match the text
1001. Set both to Text for codes. - Case:
c01does not matchC01. Uppercase both keys first. - Spaces and invisible characters: trim and clean both keys (Cleaning text and numbers in Power Query).
- Leading zeros:
00417versus417. Pad withText.PadStartor convert both to numbers.
Merging on several columns
Sometimes one column is not enough: a price list is valid per Product and Year. In the merge dialog click Product, then Ctrl+click [Cmd+click on Mac] Year in the first table, and do the same in the second table in the same order. Small numbers 1 and 2 appear in the headers to show the pairing.
= Table.NestedJoin(Sales, {"Product", "Year"}, Prices, {"Product", "Year"}, "Prices", JoinKind.LeftOuter)Expand or aggregate
The expand icon offers two modes. Expand brings columns across (one output row per match). Aggregate summarises the matching rows instead, for example the Sum of Amount of all orders per customer when you merge from Customers to Orders. Aggregate never multiplies rows, so it is the safe choice for 'total per key' questions.
Fuzzy matching
When names are typed inconsistently (Nordic Foods AS, Nordic Foods A/S, nordic foods), tick Use fuzzy matching to perform the merge in the dialog. Under Fuzzy matching options you can set the Similarity threshold (from 0 to 1, default 0.8; lower finds more but riskier matches), Ignore case, Match by combining text parts, the Maximum number of matches and a Transformation table that maps known variants to a standard name.
Check yourself
1. Which join kind keeps every order and adds the country where it exists?
Left Outer keeps all rows from the first table.
2. Which join kind lists customers who placed no orders, when Orders is the first table?
Right Anti returns rows of the second table without a match.
3. The Customers table lists C01 twice. What happens to C01 orders after a Left Outer merge and expand?
Every matching row is returned, so rows multiply.
4. The key is the number 1001 in one table and the text 1001 in the other. Will they match?
Different types never match; set both to Text.
5. Which join kind would you use to reconcile invoices against bank payments and see gaps on both sides?
Full Outer keeps unmatched rows from both sides.