Excel lookup interview question: match two tables
The lookup task almost every Excel interview includes: bring a value across from a second table. The answer interviewers want, why VLOOKUP fails here, and a sheet that grades yours.
XLOOKUP looks for a value in one range and returns the matching item from another. It replaces VLOOKUP and INDEX/MATCH: it looks left or right, it finds exact matches by default, and it can say what to show when nothing is found.
Available in Excel for Microsoft 365, Excel 2021 and later, and Excel for the web=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])| Argument | Required | What it means |
|---|---|---|
lookup_value | Yes | What you're looking for, usually a cell such as E2. |
lookup_array | Yes | The single column or row to search in. |
return_array | Yes | The column or row to bring back a value from. Same height as lookup_array. |
if_not_found | No | What to show when there's no match. Without it you get #N/A. |
match_mode | No | 0 exact (the default), -1 exact or next smaller, 1 exact or next larger, 2 wildcards. |
search_mode | No | 1 searches first to last (the default), -1 last to first. |
The code to find is in E2. XLOOKUP searches the codes in column A and returns the price on the same row from column C.
| Row | A | B | C | D | E | F |
|---|---|---|---|---|---|---|
| 1 | Code | Product | Price | Find | Price | |
| 2 | A-101 | Keyboard | $49.00 | A-103 | $189.00 | |
| 3 | A-102 | Mouse | $19.00 | |||
| 4 | A-103 | Monitor | $189.00 | |||
| 5 | A-104 | Webcam | $59.00 | |||
| 6 | A-105 | Headset | $79.00 |
=XLOOKUP(E2,A2:A6,C2:C6) → $189.00A-199 isn't in the list. The fourth argument, if_not_found, decides what appears instead of the #N/A error.
| Row | A | B | C | D | E | F |
|---|---|---|---|---|---|---|
| 1 | Code | Product | Price | Find | Price | |
| 2 | A-101 | Keyboard | $49.00 | A-199 | Not found | |
| 3 | A-102 | Mouse | $19.00 | |||
| 4 | A-103 | Monitor | $189.00 | |||
| 5 | A-104 | Webcam | $59.00 | |||
| 6 | A-105 | Headset | $79.00 |
=XLOOKUP(E2,A2:A6,C2:C6,"Not found") → Not foundVLOOKUP can only return columns to the right of the one it searches. XLOOKUP takes any return range, so finding the code for a product name, one column to the left, is the same formula shape.
| Row | A | B | C | D | E | F |
|---|---|---|---|---|---|---|
| 1 | Code | Product | Price | Find | Code | |
| 2 | A-101 | Keyboard | $49.00 | Webcam | A-104 | |
| 3 | A-102 | Mouse | $19.00 | |||
| 4 | A-103 | Monitor | $189.00 | |||
| 5 | A-104 | Webcam | $59.00 | |||
| 6 | A-105 | Headset | $79.00 |
=XLOOKUP(E2,B2:B6,A2:A6) → A-104Commission rates start at each threshold in column A. With match_mode -1, XLOOKUP returns the exact match or the next smaller threshold, so sales of 32,500 get the rate that starts at 25,000. The thresholds don't need sorting.
| Row | A | B | C | D | E |
|---|---|---|---|---|---|
| 1 | Sales from | Rate | Sales | Rate | |
| 2 | 0 | 2% | 32,500 | 6% | |
| 3 | 10,000 | 4% | |||
| 4 | 25,000 | 6% | |||
| 5 | 50,000 | 8% |
=XLOOKUP(D2,A2:A5,B2:B5,,-1) → 6%New data, so you can't copy the answer above. We check the number your formula returns, then change the data to make sure it still holds.
Your task: In F2, return the department of the employee whose ID is in E2.
Graded live| Row | A | B | C | D | E | F |
|---|---|---|---|---|---|---|
| 1 | ID | Name | Department | ID | Department | |
| 2 | 1041 | Ana Kola | Finance | 1077 | ||
| 3 | 1052 | Ben Ortiz | Sales | |||
| 4 | 1063 | Chloe Park | Marketing | |||
| 5 | 1077 | Dev Shah | Operations | |||
| 6 | 1089 | Eva Lind | Sales | |||
| 7 | 1094 | Femi Ade | Finance |
Write the formula in the bar above, then press Check or Enter.
Search the IDs in A2:A7 for the value in E2, and return from the department column, C2:C7.
=XLOOKUP(E2,A2:A7,C2:C7) Any formula that returns the same result passes.
| XLOOKUP | VLOOKUP | INDEX + MATCH | |
|---|---|---|---|
| Default match | Exact | Approximate (unless you add FALSE) | Depends on MATCH’s last argument |
| Return column to the left | Yes | No | Yes |
| Survives inserted columns | Yes | No, the column number goes stale | Yes |
| Built-in “not found” value | Yes | No, wrap it in IFNA | No, wrap it in IFNA |
| Works in Excel 2019 and older | No | Yes | Yes |
If everyone who opens the file has Microsoft 365 or Excel 2021, use XLOOKUP. If not, INDEX and MATCH does the same job everywhere.
For most lookups, yes. It finds exact matches by default, can return columns to the left, doesn't break when you insert a column, and has a built-in if_not_found. VLOOKUP is still worth knowing because older files and older Excel versions use it.
No. XLOOKUP treats a-103 and A-103 as the same value. For a case-sensitive match, combine XLOOKUP with EXACT, for example =XLOOKUP(TRUE,EXACT(A2:A6,E2),C2:C6).
Yes. Give it a return range several columns wide, such as B2:C6, and the result spills into the cells to the right. In Excel 365 and 2021 that happens automatically.
Either the function name is misspelt or your Excel version doesn't have XLOOKUP. It's in Microsoft 365, Excel 2021 and later, and Excel for the web.
Worked problems with practice sheets.
The lookup task almost every Excel interview includes: bring a value across from a second table. The answer interviewers want, why VLOOKUP fails here, and a sheet that grades yours.
#NAME? means Excel doesn't recognise a word in your formula: a misspelt function, text without quotes, a missing colon. Find it and fix it, with a practice sheet.
#REF! means a formula points at a cell that isn't there: deleted, or past the edge of a range. The usual causes and fixes, with a practice sheet.
Practise XLOOKUP and the functions around it in a live grid that grades your result and explains your mistakes.
Runs in your browser · Graded on your result · No install