Skip to content

XLOOKUP Match Mode and Search Mode

Premiumintermediate 15 min4 tasks0/90 pts

XLOOKUP has more tricks: the 5th argument match_mode finds the next larger (1) or next smaller (-1) item, and the 6th search_mode can search from the last match backwards (-1). Lookup and return ranges must be the same size.

Syntax

XLOOKUP(value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])

Example: =XLOOKUP("Ana",A2:A7,B2:B7,"none",0,-1) returns the latest order for Ana.

Common mistakes

  • Lookup and return ranges of different sizes or offset by a row.
  • Forgetting the "if not found" argument before match_mode.

When to use XLOOKUP

The last two arguments of XLOOKUP cover jobs that used to need sorted tables or array formulas. match_mode (the 5th argument) controls what counts as a match. search_mode (the 6th) controls which direction Excel searches in.

Use match_mode -1 (exact or next smaller) for tiers and bands: commission rates, tax brackets, shipping weights. Unlike VLOOKUP with TRUE, the table does not have to be sorted. Use 1 (exact or next larger) to find, for example, the cheapest box that is big enough or the first price at or above a budget.

Use search_mode -1 to search from last to first. It is the simplest way to get the most recent entry for a customer, the latest price of a product, or the last status in a log.

Worked example: Latest order for a customer

An order log lists customers in A2:A7 and amounts in B2:B7, oldest first. Ana appears three times. We want her most recent order.

CustomerAmount
Ana120
Ben80
Ana200
Cara95
Ana150
Ben60

Formula

=XLOOKUP("Ana",A2:A7,B2:B7,"none",0,-1)

  1. The first three arguments are a normal lookup: find "Ana" in A2:A7 and return from B2:B7.
  2. "none" fills the if_not_found slot. Even if you leave it empty, keep the comma, so the later arguments stay in the right position.
  3. match_mode 0 means an exact match.
  4. search_mode -1 starts at the bottom, so the first "Ana" it finds is her last order.

Result: The formula returns 150. With search_mode 1 (the default) it would return the first order, 120.

Common errors and how to fix them

  • Arguments land in the wrong slot

    match_mode is the 5th argument. If you skip if_not_found, still type the comma: =XLOOKUP(x,A:A,B:B,,-1).

  • Unexpected result with match_mode 2

    Mode 2 turns on wildcards: * and ? become patterns. Use ~* to search for a real asterisk.

  • #N/A with match_mode 1

    No value is equal to or larger than the lookup value. The lookup value is above the top of the list.

Frequently asked questions

What are the XLOOKUP match modes?

0 is an exact match (the default), -1 is exact or next smaller, 1 is exact or next larger, and 2 is a wildcard match.

What are the XLOOKUP search modes?

1 searches first to last (the default) and -1 searches last to first. 2 and -2 are binary searches for data sorted ascending or descending: they are fast on huge lists but wrong on unsorted data.

Does match_mode -1 need sorted data?

No. Unlike VLOOKUP with TRUE, XLOOKUP finds the next smaller item in an unsorted list too.

Related lessons

Function reference: XLOOKUP

Read the lesson, then try it yourself in a live spreadsheet.