Choose how XLOOKUP matches and searches
Bands, the last match and positions8 minPremium
Builds on Look up a price with XLOOKUP.
An account manager at a print shop in Minneapolis keeps a log of every order, oldest at the top. Before she calls a client, she checks their latest order, which is the last time their name appears in the log.
How it works
XLOOKUP has two more optional arguments after if_not_found. The 5th, match_mode, says what counts as a match, and the 6th, search_mode, says where to start looking.
| Row | A | B | C |
|---|---|---|---|
| 1 | Argument | Value | What it does |
| 2 | match_mode | 0 | exact match, the default |
| 3 | match_mode | -1 | exact match, or else the next smaller item |
| 4 | match_mode | 1 | exact match, or else the next larger item |
| 5 | match_mode | 2 | wildcards: * stands for any run of characters, ? for one |
| 6 | search_mode | 1 | from the first item to the last, the default |
| 7 | search_mode | -1 | from the last item to the first |
| 8 | search_mode | 2 or -2 | a fast search that assumes the list is sorted, ascending or descending |
By default XLOOKUP reads the list from the top and stops at the first match. With a search_mode of -1 it starts at the bottom, so in a log sorted oldest first, the first match it meets is the latest entry. A match_mode of -1 takes the next smaller value when there's no exact one, such as the last exchange rate published before a weekend, and 2 lets "*harbor*" find Westside Harbor Supplies.
To give a later argument and skip an earlier one, leave its place empty between commas.
Example
A print shop's maintenance log lists visits oldest first, with the date in A2:A10, the machine in B2:B10 and the technician in C2:C10. The machine to check is in B13.
=XLOOKUP(B13,B2:B10,C2:C10,"No visits",0,-1)- Step 1: XLOOKUP takes the machine in
B13, Press 2. - Step 2: With a search_mode of -1, it starts at the bottom of
B2:B10and works up. - Step 3: The first Press 2 it meets is in row 8, the latest visit. The earlier ones are never reached.
- Step 4: B14 shows the technician from that row, Lucia Gomez.
Common mistakes
=XLOOKUP(misses the empty if_not_found. The 0 becomes the fallback and the -1 the match_mode, so it still returns the first visit from the top. Count the commas: search_mode is the 6th argument.B13, B2:B10, C2:C10, 0, -1) - A search_mode of 2 or -2 assumes the list is sorted. On a log sorted by date, a fast search on the machine names can return the wrong row, or none.
"*harbor*"without a match_mode of 2 is searched for as text with real asterisks in it, and shows#N/.A
In short
- match_mode, the 5th argument: 0 exact, -1 next smaller, 1 next larger, 2 wildcards.
- search_mode, the 6th: 1 from the top, -1 from the bottom, which finds the last match.
- Leave the arguments you skip empty between commas, so each value lands in its place.
Practice
Premium4 exercises: 3 formulas and 1 quiz question.
Practice is part of Premium
Every lesson is free to read, and you can practice the free lessons without an account. This lesson's exercises are part of Premium, which you add to a free account.
Have one? Sign in