XLOOKUP
About this lesson
XLOOKUP takes the range to search and the range to return as two separate arguments. So it can look in any column and return any other.
- look up a value with XLOOKUP, with nothing to count.
- return from a column to the left of the one you searched.
- give a lookup its own not-found message.
The idea
Three of VLOOKUP's problems go away at once. There is no column number to count, so inserting a column cannot break it. The return range is separate from the lookup range, so it can sit to the left. And exact match is the default, so you do not have to remember to ask for it.
The problem is availability. XLOOKUP arrived in Microsoft 365. It is not in Excel 2019 or earlier. A workbook that must open on an older install still needs INDEX and MATCH. Learn XLOOKUP for your own sheets, and INDEX with MATCH for other people's.
The mistake to watch for
Search and return columns that start on different rows. XLOOKUP pairs them row by row. So two columns of the same height that begin one row apart return the value from the wrong row, with no error. Start both ranges on the same row. And give the fourth argument something to say when the value is missing.
Where this comes up again
This lesson needs JavaScript to run. Everything below is the lesson in full, but you cannot type into the grid or be marked.
XLOOKUP takes three things: what to find, the column to search, and the column to return from. There is no column number to count.
In E2, type =XLOOKUP(F2,A2:A5,D2:D5).
F2 is the code. A2:A5 is the codes to search. D2:D5 is the prices to return.
| Row | A | B | C | D | E | F | G |
|---|---|---|---|---|---|---|---|
| 1 | Code | Title | Stock | Price | |||
| 2 | BK-014 | Meditations | 4 | 9.99 | BK-099 | ||
| 3 | BK-241 | Sapiens | 12 | 10.99 | Wolf Hall | ||
| 4 | BK-099 | Wolf Hall | 0 | 8.99 | BK-888 | ||
| 5 | BK-571 | Normal People | 7 | 12.5 | |||
| 6 | |||||||
| 7 | |||||||
| 8 |
Every step
-
XLOOKUPtakes three things: what to find, the column to search, and the column to return from. There is no column number to count. InE2, type=XLOOKUP(F2,A2:A5,D2:D5).F2is the code.A2:A5is the codes to search.D2:D5is the prices to return. -
Read
=XLOOKUP(F2,A2:A5,C2:C5)and say what it returns. Same code, but the stock column is returned instead of the price. -
The return column can sit to the left of the searched one, which
VLOOKUPcannot do at all.F3holds a title. InE3, find its code: search the titles inB2:B5and return from the codes inA2:A5. -
A fourth argument says what to show when nothing matches.
F4holds a code that is not on the list. InE4, look it up among the codes and return the title. Make the cell say Not stocked instead of an error. -
In
E6, write a formula withXLOOKUPthat works out what the shop's copies of Sapiens are worth. That is the stock times the price. Look up both by title.