How to Find the Last Match Using XLOOKUP?
Discover how to efficiently retrieve the most recent entry of a value in a dataset using XLOOKUP's reverse search feature.
Formula Genius can generate a draft from a plain-English prompt. Supported formulas can be checked with sample cases; review the coverage on the result.
The formula
"Find the last occurrence of a value (most recent entry) using XLOOKUP with reverse search mode (-1)"
=XLOOKUP(value, range, return_range, , -1)
This formula retrieves the last occurrence of a specified value from a range by searching in reverse order.
Step-by-step breakdown
- Specify the value you want to find.
- Define the range where the value is searched.
- Indicate the return range from which to pull the corresponding result.
- Use -1 as the fourth argument to enable reverse search mode.
Edge cases & warnings
- The value does not exist in the range, resulting in an error.
- Multiple identical values are present, and the last one is returned correctly.
- The search range is empty, leading to an error.
- The return range is shorter than the search range, causing a mismatch.
Examples
"XLOOKUP("apple", A1:A5, B1:B5, , -1) where A1:A5 = {"banana", "apple", "orange", "apple", "grape"} and B1:B5 = {1, 2, 3, 4, 5}"
4
"XLOOKUP("orange", A1:A5, B1:B5, , -1) where A1:A5 = {"banana", "apple", "orange", "apple", "grape"} and B1:B5 = {1, 2, 3, 4, 5}"
3
Frequently asked questions
What happens if the value is not found?
The formula will return an error indicating that the value is not found.
Can I use XLOOKUP with non-contiguous ranges?
No, XLOOKUP requires contiguous ranges for both the lookup and return ranges.
Is XLOOKUP available in all versions of Excel?
XLOOKUP is available in Excel 365 and Excel 2021 and later versions.
Can't find what you need?
Describe a formula in plain English. Formula Genius drafts and explains it, and can check supported formulas on sample cases.