Start free

Excel lookup interview question: match two tables

Works in XLOOKUP: Excel 365, 2021 and later; INDEX and MATCH: every version

Key takeaways

  • Say what you're matching on first: the ID, the column it sits in, and the column you need back.
  • XLOOKUP is exact by default, can return a column to the left, and has its own "not found" value.
  • INDEX with MATCH does the same in every version of Excel. MATCH needs 0 at the end for an exact match.
  • VLOOKUP can't return a column to the left of the one it searches, which is exactly what this task needs.
  • Mention the missing-ID case before they ask: it's the follow-up question almost every time.
Jump straight to the practice sheet
On this page

The answer interviewers want is =XLOOKUP(F2,$C$2:$C$5,$A$2:$A$5,"Not found"): find the ID in the staff table’s ID column and return the name from the column you need, with a fallback for an ID that isn’t there. In a file that must open in Excel 2019 or older, write the same lookup as =IFNA(INDEX($A$2:$A$5,MATCH(F2,$C$2:$C$5,0)),"Not found") (IFNA needs Excel 2013 or later; before that, use IFERROR). A plain VLOOKUP can’t answer this one, because the names sit to the left of the IDs.

The question

“Here’s an orders sheet and a staff list. Each order only has the staff ID of the rep who took it. Add a column to the orders that shows the rep’s name, and make it work when we paste in next month’s orders.”

It sounds like a quick task, and it is, once you’ve read both tables properly. Most candidates who stumble do so because they start typing before they’ve looked at which column holds what.

What they’re really testing

  • That you read the data first. Which column is the key (the staff ID), where it sits in each table, and where the value you need back (the name) is.
  • That you pick a lookup that fits. The IDs are in column C of the staff table and the names in column A, to their left. That rules out a plain VLOOKUP.
  • That you match exactly. A lookup that quietly returns a neighbour’s name is worse than an error.
  • That you plan for a missing ID. Real data always has one: a new hire, a typo, a leaver.

The worked answer

The staff list is in A1:C5, the orders in E1:G4. The formula goes in G2 and is copied down to G4:

G2=XLOOKUP(F2,$C$2:$C$5,$A$2:$A$5,"Not found")
RowABCDEFG
1NameTeamStaff IDOrderStaff IDRep
2Lena HartNorthS-104O-5531S-117Omar Diaz
3Omar DiazSouthS-117O-5532S-104Lena Hart
4Priya ShahNorthS-121O-5533S-140Not found
5Tom OkaforWestS-130

That’s XLOOKUP. Read it out loud the way you would in the interview: “Find F2 in the staff IDs, C2 to C5, and return the matching name from A2 to A5. If it isn’t there, show Not found.” Order O-5531 was taken by S-117, Omar Diaz.

If the interviewer says the file goes to people on an older version of Excel, give the INDEX and MATCH version. MATCH finds the row of the ID in the list, and INDEX returns the name on that row:

=INDEX($A$2:$A$5,MATCH(F2,$C$2:$C$5,0)) → Omar Diaz

The $ signs are what make it copy. Without them, the formula in G3 would search C3:C6, a range that starts below Lena Hart’s row, and order O-5532 would show “Not found” for a rep who is on the list:

Wrong=XLOOKUP(F3,C3:C6,A3:A6,"Not found")Not found
Right=XLOOKUP(F3,$C$2:$C$5,$A$2:$A$5,"Not found")Lena Hart

Why VLOOKUP fails here

VLOOKUP searches the first column of the table you give it and can only return columns to its right. Give it A2:C5 and it searches the names, so no ID is ever found:

Wrong=VLOOKUP(F2,$A$2:$C$5,1,FALSE)#N/A
Right=XLOOKUP(F2,$C$2:$C$5,$A$2:$A$5,"Not found")Omar Diaz

The old workarounds, moving the ID column to the left or building a helper column, change the client’s data to suit the formula. XLOOKUP and INDEX with MATCH take the search column and the return column separately, so neither needs it. (VLOOKUP over a table rebuilt with CHOOSE also works, but it’s harder to read and to check than either.) For the full comparison, see XLOOKUP vs VLOOKUP.

The follow-up: an ID that isn’t there

Order O-5533 has staff ID S-140, which isn’t in the list. With the fallback, G4 says so plainly:

=XLOOKUP(F4,$C$2:$C$5,$A$2:$A$5,"Not found") → Not found

The dangerous version is a lookup that doesn’t match exactly. MATCH without its last argument assumes the IDs are sorted and returns the closest one below. S-140 isn’t there, so it returns the row of S-130, and the order is credited to Tom Okafor with no error at all:

Wrong=INDEX($A$2:$A$5,MATCH(F4,$C$2:$C$5))Tom Okafor
Right=XLOOKUP(F4,$C$2:$C$5,$A$2:$A$5,"Not found")Not found

VLOOKUP without FALSE does the same. That’s why interviewers watch for the last argument: it’s the difference between an obvious gap and a quietly wrong commission report.

Common wrong answers, and why they fail

  1. VLOOKUP on the whole table. It searches the names, not the IDs, and returns #N/A for every order.
  2. MATCH or VLOOKUP without the exact-match flag. It works on the sample, then credits a missing ID to someone else.
  3. No plan for a missing ID. A column full of #N/A in a report you hand on. Use XLOOKUP’s fourth argument or IFNA, and don’t use IFERROR, which also hides a broken formula (why #N/A appears covers the other causes).
  4. Ranges that move when copied. Without $ signs, each row’s lookup searches a smaller list, and early rows go missing.
  5. The wrong return column. Returning the team instead of the name. Read the header before you point at the range.
  6. Typing the names in by hand. It answers today’s orders and none of next month’s. The interviewer said “make it work when we paste in new orders” for a reason.

Practise it: return the owner, or “Not found”

New staff, new IDs and a ticket table in place of the orders, so the formula above won’t fit as it is. We check the name your formula returns, then change the ID, including one that isn’t in the list.

Your task: In G2, return the name of the person whose ID is in F2, or the text "Not found" when that ID isn't in the staff list.

Graded live
RowABCDEFG
1NameDeptEmp IDTicketEmp IDOwner
2Ana KolaFinanceE-210T-901E-233
3Ben OrtizSalesE-224
4Chloe ParkOpsE-233
5Dev PatelSalesE-247
6Eva NovakFinanceE-251

Write the formula in the bar above, then press Check or Enter.

Hint

Search the IDs in C2:C6 and return from the names in A2:A6. Give XLOOKUP "Not found" as its fourth argument, or wrap INDEX and MATCH (with 0) in IFNA.

Solution

=XLOOKUP(F2,C2:C6,A2:A6,"Not found") Any formula that returns the same result passes.

How to answer it in the interview

Name the key, the column to search, the column to return and the missing case in one breath: “I’ll match on the staff ID, look it up in the ID column and return the name, exact match, with Not found for any ID that’s missing. XLOOKUP if we’re on Microsoft 365, INDEX and MATCH if the file has to work in older versions, with the ranges locked before I copy it down.” That sentence answers the follow-up questions before they come. More questions like this one: Excel interview questions.

Practise this in a lessonLook up to the left with INDEX and MATCHA full exercise in the app's live grid, graded on what your formula calculates.Open the lesson

FAQ

Should I answer with VLOOKUP or XLOOKUP in an Excel interview?

Use XLOOKUP if the company runs Microsoft 365, and say why: exact by default, no column number to count. Then show you also know INDEX and MATCH, which works in every version. If they ask for VLOOKUP by name, write it with FALSE at the end.

Why do interviewers still ask about VLOOKUP?

Many company files are full of it, so they want to know you can read and fix one. Know its weak points: the column number, and the FALSE that makes it exact.

What's the difference between INDEX MATCH and XLOOKUP?

They give the same results for an exact lookup. XLOOKUP is one function with a built-in "not found" value; INDEX and MATCH are a pair, work in older versions, and need IFNA for a missing value.

What if the ID appears twice in the lookup table?

XLOOKUP, VLOOKUP and MATCH all return the first match from the top. If the latest one matters, XLOOKUP can search from the bottom with -1 as its sixth argument, the search mode.

Summarize this guide withChatGPTPerplexityClaude

Keep going

Guides that build on this one.

All guides
Modern Excel

XLOOKUP vs VLOOKUP: which should you use?

XLOOKUP does everything VLOOKUP does with fewer ways to go wrong. Here's the same lookup written both ways, the five differences that matter, and when VLOOKUP is still the right call.

2 min read · Updated
Errors & fixesPractice sheet

#N/A error in Excel: what it means and how to fix it

#N/A means a lookup didn't find what it was looking for. Here are the six usual causes, how to spot each one on the sheet, and the fix, with a practice sheet.

2 min read · Updated
Interview prepPractice sheet

Excel data cleaning interview question

Extra spaces, names in the wrong order, numbers stored as text and dates that aren't dates: the cleaning task interviewers love, solved with formulas, and a sheet that grades yours.

4 min read · Updated

Reading is step one. Writing the formula is the skill.

Practise in a live grid that grades what your formula calculates, with a specific hint when it's wrong.

Runs in your browser · Graded on your result · No install