XLOOKUP: Find the Last Match

Excel Formulas › Lookup

365 / 2021XLOOKUP

Need the most recent entry — the last price, the latest status? XLOOKUP’s search mode can scan from the bottom up, returning the last match instead of the first.


Quick formula: find the last row matching A2:
=XLOOKUP(A2, ids, values, , 0, -1)
The 6th argument is search mode: -1 searches last-to-first, so you get the most recent matching record.

Functions used (tap for the full reference guide):

The example

The latest price for a repeated product.

AB
1Product (log)Price
2Widget10
3Widget12 (latest)

The formula

Search from the bottom:

=XLOOKUP(A2, products, prices, , 0, -1) // -1 search mode = last match

How it works

Search mode sets the scan direction:

  1. The 6th argument is search mode: 1 first-to-last (default), -1 last-to-first.
  2. With -1, XLOOKUP returns the last row that matches — the most recent in a chronological log.
  3. The 4th and 5th arguments (if_not_found, match mode) still go in their slots; use commas to skip them.
  4. For sorted data, search modes 2 and -2 enable fast binary search.

Pre-XLOOKUP last match needed an array LOOKUP trick: =LOOKUP(2, 1/(products=A2), prices) returns the last match in any version. XLOOKUP’s search mode -1 is the readable modern replacement.

Try it: interactive demo

Live demo

Latest price for the product.

Latest price:

Variations

First match (default)

Omit search mode:

=XLOOKUP(A2, products, prices)

Legacy last match

Any version:

=LOOKUP(2, 1/(products=A2), prices)

Binary search

Sorted data, fast:

=XLOOKUP(A2, sorted, vals, , 0, 2)

Pitfalls & errors

Count the commas. Search mode is the 6th argument; skip if_not_found and match mode with commas: XLOOKUP(v, l, r, , 0, -1).

“Last” assumes order. Last-to-first returns the last row, which is only “most recent” if the data is in chronological order.

365/2021 only. Use the LOOKUP(2,1/(...)) trick in older Excel.

Practice workbook

📊
Download the free XLOOKUP: Find the Last Match practice workbook
XLOOKUP last-match examples (formula text + result) with first-match, legacy, and binary variants, plus 4 challenges with answers. No sign-up required.

Frequently asked questions

How do I find the last match with XLOOKUP?
Set the search-mode argument to -1: =XLOOKUP(value, lookup, return, , 0, -1) scans bottom-up and returns the last match. Requires Excel 365/2021.
How do I get the last match in older Excel?
Use the array trick =LOOKUP(2, 1/(range=value), returnRange), which returns the last matching value in any version.
Where does the search mode go in XLOOKUP?
It's the sixth argument. Skip if_not_found and match mode with commas: =XLOOKUP(v, l, r, , 0, -1).

Stop fighting formulas. Learn them in a day.

This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.

See the Formulas & Functions Class

Related formulas: Last match (lookup) · Lookup nth match · XLOOKUP if not found

Function references: XLOOKUP