How to Merge Two Tables in Excel With XLOOKUP or Power Query
By ExcelReady TeamUpdated 6 min read
The short answer
To merge two tables in Excel, match them on a shared column such as a customer ID. With formulas, add XLOOKUP to the first table, for example =XLOOKUP(B2,$E$2:$E$4,$F$2:$G$4,"Not found"), to bring columns across. With Power Query, load both tables and use Merge Queries with a Left Outer join. Power Query suits large tables you refresh often.
Key takeaways
- Merging means joining two tables on a shared key column, such as an ID, so each row gains columns from the other table.
- XLOOKUP can return several columns at once and shows your own text when a key has no match.
- VLOOKUP with FALSE does the same job in older Excel, one column at a time.
- Power Query's Merge Queries joins whole tables, offers join types like Left Outer and Inner, and refreshes in one click.
- Most failed matches come from extra spaces or numbers stored as text in the key column.
On this page+
To merge two tables in Excel, you match their rows on a column they share, such as a customer ID, and bring the other table's columns across. You can do it with a lookup formula like XLOOKUP, which updates instantly, or with Power Query's Merge Queries, which joins whole tables and refreshes in one click. This guide shows both on the same small example, plus VLOOKUP for older Excel and fixes for rows that don't match.
What merging two tables means#
Merging, also called joining, puts two tables side by side. A key column links them: a value that appears in both, like an order's customer ID and the ID in a customer list. Each row in the first table gains the matching columns from the second.
That's different from appending, which stacks two tables with the same columns on top of each other, such as January and February sales. If that's what you need, use Power Query's Append Queries or, in Microsoft 365, the VSTACK function.
The example tables#
An orders table in A1:C6 has a customer ID but no customer details. A customer table in E1:G4 has the details:
| Order | Customer ID | Amount |
|---|---|---|
| 1001 | C-102 | 250 |
| 1002 | C-101 | 400 |
| 1003 | C-104 | 150 |
| 1004 | C-102 | 320 |
| 1005 | C-103 | 180 |
| ID | Name | Region |
|---|---|---|
| C-101 | Amara | North |
| C-102 | Ben | South |
| C-103 | Chen | East |
Customer C-104 is missing from the customer table on purpose, so you can see what happens to a row with no match. The tables can be on different sheets; the guide to VLOOKUP between two sheets shows how the references look then.
Merge two tables with XLOOKUP#
XLOOKUP finds a value in one column and returns the matching value from another. In D2, next to the first order:
=XLOOKUP(B2,$E$2:$E$4,$F$2:$F$4,"Not found")It looks for C-102 in the ID column and returns Ben. The fourth argument, "Not found", is shown instead of an #N/A error when a key is missing. Fill it down (Windows: Ctrl+D; Mac: ⌘D); the $ signs keep the customer table fixed as the formula moves. XLOOKUP needs Excel 2021 or Microsoft 365. The XLOOKUP function guide lists every argument, and the article on how to use XLOOKUP covers match modes and errors.
Bring back several columns at once#
XLOOKUP can return more than one column if the return range is wider. To get both Name and Region:
=XLOOKUP(B2,$E$2:$E$4,$F$2:$G$4,"Not found")The result spills into D2:E2: Ben in D2 and South in E2. Fill it down and the merged table looks like this:
| Order | Customer ID | Amount | Name | Region |
|---|---|---|---|---|
| 1001 | C-102 | 250 | Ben | South |
| 1002 | C-101 | 400 | Amara | North |
| 1003 | C-104 | 150 | Not found | Not found |
| 1004 | C-102 | 320 | Ben | South |
| 1005 | C-103 | 180 | Chen | East |
The cells to the right must be empty, or you get a #SPILL! error. For more on returning whole rows, see XLOOKUP with multiple columns.
Merge with VLOOKUP in older Excel#
VLOOKUP does the same job in every version of Excel, one column at a time. For Name, in D2:
=VLOOKUP(B2,$E$2:$G$4,2,FALSE)The 2 means "return the second column of E:G", and FALSE asks for an exact match. For Region, change the 2 to 3. VLOOKUP shows #N/A for C-104, so wrap it to show your own text: =IFNA(VLOOKUP(B2,$E$2:$G$4,2,FALSE),"Not found"). The key must be the first column of the lookup range, because VLOOKUP only looks to the right. The VLOOKUP function guide explains each argument.
Merge two tables with Power Query#
Power Query joins whole tables without formulas. It is built into Excel 2016 and later on Windows, and into Microsoft 365 on Mac. Follow these steps:
- Click inside the orders data and choose Insert > Table. On the Table Design tab, name it Orders. Do the same for the customer data and name it Customers.
- With a cell in Orders selected, choose Data > From Table/Range. In the Power Query Editor, choose Home > Close & Load To, then Only Create Connection. Repeat for Customers.
- Choose Data > Get Data > Combine Queries > Merge.
- Pick Orders in the top box and Customers in the bottom box. Click the Customer ID column in the top preview and the ID column in the bottom one.
- Leave Join Kind as Left Outer (all rows from the first table, matching rows from the second) and click OK.
- A new column holds the matching customer rows. Click the expand button in its header, tick Name and Region, untick "Use original column name as prefix", and click OK.
- Choose Home > Close & Load. The merged table appears on a new sheet.
When the orders or customers change, choose Data > Refresh All and the merge runs again. Other join kinds change which rows you keep: Inner keeps only orders with a matching customer, so order 1003 disappears, and Left Anti keeps only the orders with no match, which is a quick way to find problems. New to Power Query? Start with Power Query for beginners.
Formula or Power Query: which to use?#
Both give the same merged table here. Pick by the job:
| Situation | Better choice |
|---|---|
| A quick one-off merge of a few columns | XLOOKUP or VLOOKUP |
| Results must update the moment you type | XLOOKUP or VLOOKUP |
| Tens of thousands of rows, or many columns | Power Query |
| The same merge every week from new exports | Power Query |
| You need inner, anti or full outer joins | Power Query |
| A job test asks for a formula | XLOOKUP, or VLOOKUP if named |
One key difference: if a customer ID appears twice in the customer table, XLOOKUP and VLOOKUP return only the first match. Power Query returns every match, so an order row can turn into two rows. Check the key column for duplicates before you merge.
Why do some rows not match?#
When a merge shows Not found or #N/A for a key you can see in both tables, the keys aren't exactly the same. Check these:
- Extra spaces. "C-102 " with a trailing space doesn't match "C-102". Clean the column with TRIM.
- Numbers stored as text. An ID of 1001 as a number doesn't match "1001" as text. Convert one side with VALUE, or with
B2&""to turn numbers into text. - Different formats. "C102" and "C-102" are different keys. Standardise them with SUBSTITUTE first.
To see which keys are missing from either table before you merge, compare the two lists.
Practise it#
Try the exercise on this page: one XLOOKUP brings a region into the orders table. Then practise XLOOKUP in a live spreadsheet and work through the VLOOKUP practice lesson. Both check your formulas as you type, so you'll be ready for the lookup questions in a job test.
Try it yourself
This is a live spreadsheet. Type the formula in the green cell and press Enter.
Bring each order's region across from the customer table. Click D2 and use XLOOKUP to find the customer ID in B2 in E2:E4, return the region from G2:G4, and show "Not found" if there's no match. Press Enter.
| A | B | C | D | E | F | G | H | |
|---|---|---|---|---|---|---|---|---|
| 1 | Region | |||||||
| 2 | North | |||||||
| 3 | South | |||||||
| 4 | East | |||||||
| 5 | ||||||||
| 6 | ||||||||
| 7 | ||||||||
| 8 |
Tip: XLOOKUP needs what to find (B2), where to look (E2:E4), what to return (G2:G4), and then the text for no match.
Practise this in a lesson
Frequently asked questions
How do I merge two tables with a common column in Excel?
Add a lookup formula to the first table that finds each key in the second table and returns the columns you need, such as =XLOOKUP(B2,$E$2:$E$4,$F$2:$G$4,"Not found"). For large or repeated jobs, use Power Query's Merge Queries instead.
Can I merge tables in Excel without formulas?
Yes. Power Query can do it: load both tables, choose Data > Get Data > Combine Queries > Merge, pick the matching columns and expand the columns you want. The result is a new table you can refresh.
What happens to rows that have no match?
XLOOKUP returns its if_not_found text, such as Not found, and VLOOKUP returns #N/A. In Power Query, a Left Outer join keeps the row with empty values, while an Inner join drops it.
How is merging different from appending tables?
Merging joins tables side by side on a key, adding columns. Appending stacks tables with the same columns on top of each other, adding rows. Use Power Query Append or VSTACK in Microsoft 365 to append.