Practice problems / Lookup & Reference

XLOOKUP misses without blowing up (IFERROR)

Medium Lookup & Reference
Description
Hints 0/4
Solutions 2
–
Test case
1
2
3
Reset
Submit
fx
A
B
C
D
E
F
G
1
2
3
4
5
6
7
8
9
10
Loading interactive spreadsheet...
Preparing grid cells and formula calculation engine
○ Ready Enter formula in highlighted cells, then click Submit.

The problem

Problem statement

Customer service keeps typing SKUs that stopped existing, and every miss splatters #N/A across the price report. Look up the price for the SKU in E2 from the list in A2:C6, and return the text "Not found" instead of an error. Fill the Price cell F2 — two ways solve this, and one of them doesn't even need IFERROR.

Put the fallback in the second argument (or XLOOKUP's 4th) — case 2 is unmatched and must return "Not found", never #N/A.

Problem data

Show the sheet as a table (selectable, copyable)
The exercise data, as a table
ABCEF
1 SKUProductPriceLookup SKUPrice
2 SKU-1001Kettle89SKU-1043
3 SKU-1017Mug12
4 SKU-1043Teapot249
5 SKU-1088Tray35
6 SKU-1102Coaster9

Notes

Two idiomatic fixes. The classic: wrap the lookup — =IFERROR(XLOOKUP(…), "Not found"). The modern one: XLOOKUP has a built-in 4th argument, if_not_found — =XLOOKUP(E2, A2:A6, C2:C6, "Not found") handles misses natively with no wrapper. Prefer the 4th argument when your audience has modern Excel: it only traps misses, whereas IFERROR also swallows real breakage like #REF! from deleted columns.

How to approach

Your answer goes in F2. On submit we re-run your formula against 3 different sets of input, so a hardcoded number will fail — the formula has to follow the cells.

  1. Target cell is F2
  2. The raw lookup is the XLOOKUP you already know: ID in E2, names in A2:A6, salaries in C2:C6
  3. IFERROR wraps it — the lookup first, the fallback second
  4. Preferred in modern Excel: XLOOKUP's own 4th argument (if_not_found) needs no wrapper at all

Official solutions

Show 2 solutions — try it yourself first

Approach 1: IFERROR around the lookup

=IFERROR(XLOOKUP(E2, A2:A6, C2:C6), "Not found")

The lookup returns a price when the SKU exists and #N/A when it doesn't. IFERROR converts the #N/A into "Not found" — works in every Excel version and in Google Sheets.

Approach 2: XLOOKUP's built-in if_not_found

=XLOOKUP(E2, A2:A6, C2:C6, "Not found")

The 4th argument exists exactly for this: no match → return this value. No wrapper, one function, and unlike IFERROR it can never mask unrelated errors.

Function guide

Related practice

FAQ

How do I make XLOOKUP return blank instead of #N/A?

Use the 4th argument: =XLOOKUP(E2, A2:A6, C2:C6, "") returns an empty-looking cell on a miss. For a visible message use =XLOOKUP(E2, A2:A6, C2:C6, "Not found").

IFERROR or XLOOKUP's if_not_found — which should I use?

With modern Excel or Google Sheets, prefer the 4th argument: it traps only misses. IFERROR(x, y) also hides #REF!, #VALUE!, and #DIV/0! — convenient, but it can hide structural breakage a miss never would.

Does Google Sheets XLOOKUP support if_not_found?

Yes. Sheets' XLOOKUP has the same 4th argument, so =XLOOKUP(E2, A2:A6, C2:C6, "Not found") works identically. On very old Excel versions without XLOOKUP, use =IFERROR(VLOOKUP(…), "Not found") instead.