Excel Supreme

Excel track · Exercise 40 of 86 Paid

XLOOKUP with a fallback when nothing matches

Answer a missing SKU with a sentence instead of an error.

Intermediate

A three-SKU price list

Read-only data · answer in B6

In B6, look up the price of the SKU in B5, and return "not stocked" when the list has no such SKU.

AB
1SKUPrice
2TX-10119.99
3TX-10214
4TX-1039.5
5LookupTX-104
6Price

Download this grid (.xlsx) Two tabs: the grid you see, and the answer.

B6

What it does

The list holds three SKUs and B5 asks for TX-104, which is not among them. A three-argument XLOOKUP would answer #N/A, and a column of #N/A sends the reader to the formula bar to work out what went wrong.

The fourth argument is the text to show instead. XLOOKUP returns "not stocked" and the cell reads as a sentence. That text appears exactly as typed, so the lower case in the prompt is part of the answer.

Use it on sheets that other people read. The fallback should say what is missing, and it should never be a zero, because a zero passes for a price.

Syntax

=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found])

Worked example

On A three-SKU price list, =XLOOKUP(B5,A2:A4,B2:B4,"not stocked") returns not stocked.

=XLOOKUP(B5,A2:A4,B2:B4,"not stocked")

Common errors

Error codes for XLOOKUP fallback
ErrorWhat it means and how to fix it
#N/ANo fallback was supplied, so a SKU that is not in A2:A4 came back with nothing to say.
#VALUE!The search column and the return column are different sizes, and some rows have no partner.

At work

A stock sheet where a discontinued SKU has to read as out of stock in an email, rather than #N/A.