Stop 04 · Power Query TransformationsTopics · 9/11

Merge Queries (Joins in Power Query)

Part of the Power BI Roadmap

In short

Your sales file has a ProductID but no product name. Merge Queries brings in columns from another table by matching keys, the Power Query version of a SQL join or an Excel lookup.

Merge Queries joins two queries on matching columns, with join kinds like left outer, inner, full outer and anti joins, similar to SQL joins.

The jaadu carries a stack of tiffin boxes with coloured lids and matches each one to a desk with the same colour flag in a busy office.

Think of it like this

Matching tiffins to desks

Each tiffin has a desk number painted on the lid. The delivery person matches the number to the office seating chart to find who sits there. Merge Queries matches ProductID on each sale to the products list to find its name and category.

Watch it happen

Left outer vs left anti

Left outer

  • Keeps every sales row
  • Adds product name and category where a match exists
  • Unmatched rows get null
  • The everyday default

Left anti

  • Keeps only sales rows with NO match
  • Great for finding missing product codes
  • Used for data quality checks
  • Not for normal loading

Use left outer to enrich data. Use left anti as a detective tool to find keys that don't match before they cause blank categories in visuals.

The big ideas

What you need to know

Six join kinds

Left outer, right outer, full outer, inner, left anti and right anti, the same ideas as SQL joins.

Matching keys

Keys must match exactly in value and type. ' P101' with a space will not match 'P101'.

Expand after merging

The merge adds a column of nested tables. Click the expand icon and pick only the columns you need.

Merge or relationship?

Often a relationship in the model is better than a merge. Merge when you need to flatten small lookup info or check matches.

See it in code

Walk through the code

m
1let2    Merged = Table.NestedJoin(3        Sales, {"ProductID"},4        Products, {"ProductID"},5        "Product",6        JoinKind.LeftOuter7    ),8    Expanded = Table.ExpandTableColumn(9        Merged, "Product",10        {"ProductName", "Category"},11        {"Product Name", "Category"}12    ),13    Unmatched = Table.NestedJoin(14        Sales, {"ProductID"}, Products, {"ProductID"},15        "Product", JoinKind.LeftAnti16    )17in18    Expanded

1/3Match Sales[ProductID] to Products[ProductID] with a left outer join, storing matches in a column called Product.

Enrich Sales with product name and category, plus a left anti check that lists sales with unknown product codes.

Save yourself the pain

Common mistakes

Oops

Merging on a key that has duplicates in the lookup table.

Do this instead

Remove duplicates on the key in the lookup table first, or every sales row may be multiplied.

Oops

Expanding every column from the merged table.

Do this instead

Untick Use original column name as prefix if you like, and pick only the columns you need.

Your mission

Enrich and investigate

~25 min

Quick check

Which join kind returns only the rows from the first table that have no match in the second?

Go deeper

  1. 1Merge an orders table with a customers table to bring in the region.
  2. 2Try a left anti join to find orders with no matching customer.
  3. 3Ask whether a relationship in the model would be better than a merge.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge