Skip to content

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.

RowABC
1ArgumentValueWhat it does
2match_mode0exact match, the default
3match_mode-1exact match, or else the next smaller item
4match_mode1exact match, or else the next larger item
5match_mode2wildcards: * stands for any run of characters, ? for one
6search_mode1from the first item to the last, the default
7search_mode-1from the last item to the first
8search_mode2 or -2a 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)
Searches B2:B10 from the bottom up for the machine in B13 and returns the technician from its latest visit, or No visits.

  1. Step 1: XLOOKUP takes the machine in B13, Press 2.
  2. Step 2: With a search_mode of -1, it starts at the bottom of B2:B10 and works up.
  3. Step 3: The first Press 2 it meets is in row 8, the latest visit. The earlier ones are never reached.
  4. Step 4: B14 shows the technician from that row, Lucia Gomez.
With a search_mode of -1, XLOOKUP starts at the bottom, so the first match it meets is the latest visit. In B14, =XLOOKUP(B13,B2:B10,C2:C10,"No visits",0,-1) returns Lucia Gomez.

Common mistakes

  • =XLOOKUP(B13,B2:B10,C2:C10,0,-1) 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.
  • 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

Premium

4 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.