Merge queries in Power Query

Merging fetches matching columns from a second table, like VLOOKUP or XLOOKUP in Excel. Here you learn how it works in Power Query, and when a relationship in the model is the better choice.

In short: select the key column, Merge Queries, pick the second query and its matching column. You get a column of tables; Expand fetches the columns you want from it. The default "Left Outer" join keeps every row of the first query.

Prerequisites: Split columns and data types.

Try it now

This exercise has two queries: Orders on the left, Products on the right. Select the key column first.

Task Each order is missing the product name and price, which are in the Products query. Merge Orders with Products on ProductID, then expand Product and Price.

ABCDEFG
1 OrderID ProductID Quantity ProductID Product Price
2 101 2 3 1 Laptop 899
3 102 1 1 2 Monitor 229
4 103 4 5 3 Mouse 19.9
5 104 2 2 4 Keyboard 39.9
6 105 3 10

How merging works

For every row of the first query, Power Query looks for the rows of the second with the same key. The result first lands as a nested table in a new column, because there could be several matches. Only Expand fetches individual columns. You usually untick "Use original column name as prefix", otherwise the columns are called Products.Price.

Join kindResult
Left Outer (default)every row of the first query, matching ones from the second; null where there is no match
Inneronly rows with a match in both
Left Antionly rows of the first without a match, handy for finding gaps

Merge or relationship?

Power BI has a second route: load both tables and connect them with a relationship in model view (level 3). Rule of thumb: if the report only needs one or two columns from the second table, merge. If it has many columns that also feed slicers and filters (products, customers, dates), it becomes a dimension table of its own with a relationship.

One more exercise: what happens without a match?

Task Every customer should get their sales territory. Merge Customers with Territories on State and expand Territory. One customer has a state that is missing from Territories: what does that customer get?

ABCDE
1 Customer State State Territory
2 Baker Ltd TX TX South
3 Lindsay & Co OH GA South
4 Oakwood plc GA OH Midwest
5 Reid Supplies WA WA West
6 Khan Trading NV

This exercise is part of Premium.

Premium unlocks every exercise in every lesson, unlimited practice with fresh tasks and the final test with certificate.

See Premium Already Premium? Log in

The first exercise in this lesson is free.

In real Power BI

  1. Merge: Home, Merge Queries. For the result in a new query, use "Merge Queries as New".
  2. In the dialog: click the first query's key column at the top, then the second query and its column below. Power Query shows how many rows match.
  3. Expand: click the two-arrow icon in the new column header and tick the columns.

Common mistakes

Keys with different types

If ProductID is text in one table and a number in the other, Power Query finds not a single match. Align the data types first.

Several matches

If a key appears twice in the second table, Expand duplicates the row of the first table. The sales in the report would then be too high. Check the second table for duplicates first.

Spaces in the key

"P-100 " and "P-100" do not match. Trim first, then merge.

Frequently asked questions

Is merging the same as a JOIN in SQL?

Yes, for databases Power Query even translates it into a SQL JOIN. The join kinds have the same names: left, inner, full, anti.

Can I merge on several columns?

Yes. In the dialog, hold Ctrl and click the columns in both tables one after another; the order has to match.

Learn this next: append queries

Stack monthly files and branch exports into one table.

Append queries

Write to us

Choose language

Select your preferred language