To use XLOOKUP in Excel, you input a value you're searching for and specify the ranges where Excel should look for it and where it should find the corresponding result. It's a versatile function designed to perform powerful lookups, often replacing older functions like VLOOKUP and HLOOKUP due to its enhanced flexibility and features.
The fundamental formula structure for XLOOKUP is:
=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])
Excel requires you to fill in the first three arguments, while the last three are optional and provide additional control over the lookup process.
Understanding XLOOKUP Arguments
Here's a breakdown of each argument and its purpose:
Argument | Description | Required/Optional |
---|---|---|
lookup_value |
The item you are looking for (e.g., a product ID, an employee name). This can be text, a number, or a cell reference. | Required |
lookup_array |
The range of cells where XLOOKUP should search for the lookup_value . |
Required |
return_array |
The range of cells from which the corresponding result should be returned. This must be the same size as lookup_array . |
Required |
[if_not_found] |
(Optional) The value to return if no match is found. If omitted, XLOOKUP returns the #N/A error. |
Optional |
[match_mode] |
(Optional) Specifies the type of match to perform: • 0 (default): Exact match • -1 : Exact match or next smaller item • 1 : Exact match or next larger item • 2 : Wildcard character match |
Optional |
[search_mode] |
(Optional) Specifies the search direction: • 1 (default): Search from the first item to the last • -1 : Search from the last item to the first • 2 : Binary search (ascending sort required) • -2 : Binary search (descending sort required) |
Optional |
Practical Examples and Usage Scenarios
XLOOKUP's power comes from its ability to handle various lookup needs with a single function.
1. Basic Exact Match Lookup
The most common use is to find an exact match and return a corresponding value.
- Scenario: You have a list of product IDs in column A and their prices in column B. You want to find the price of a specific product ID.
- Formula:
=XLOOKUP(D2, A:A, B:B)
D2
: The cell containing the product ID you want to look up.A:A
: The column where product IDs are located.B:B
: The column containing the prices you want to return.
2. Handling Missing Values with if_not_found
Avoid #N/A
errors by specifying what to return if no match is found.
- Scenario: Continuing the product example, if a product ID isn't found, you want to display "Product Not Found".
- Formula:
=XLOOKUP(D2, A:A, B:B, "Product Not Found")
- If
D2
's value isn't in columnA
, the cell will display "Product Not Found" instead of#N/A
.
- If
3. Approximate Matching for Ranges
Useful for pricing tiers, tax brackets, or grading systems.
- Scenario: You have sales volumes in column A and corresponding commission rates in column B. You want to find the commission rate for a given sales volume, even if the exact volume isn't listed.
- Formula:
=XLOOKUP(D2, A:A, B:B, "", -1)
D2
: The sales volume.A:A
: Column with sales volume thresholds (must be sorted ascending for approximate matches).B:B
: Column with commission rates.-1
: Specifies an exact match or the next smaller item, which is ideal for "less than or equal to" scenarios like commission tiers.
4. Wildcard Character Matching
For partial matches where you only know part of the lookup_value
.
- Scenario: You want to find an employee's ID when you only know part of their name, like "John*".
- Formula:
=XLOOKUP("John*", A:A, B:B, "", 2)
"John*"
: Thelookup_value
using a wildcard (*
for any sequence of characters).A:A
: Column with employee names.B:B
: Column with employee IDs.2
: Enables wildcard character matching.
5. Reverse Searching
Finding the last occurrence of a value, rather than the first.
- Scenario: You have multiple entries for a project in a log, and you want to find the latest status update (which would be the last entry in the list).
- Formula:
=XLOOKUP(D2, A:A, B:B, "", 0, -1)
D2
: The project ID you're looking for.A:A
: The column containing project IDs.B:B
: The column with status updates.-1
: Tells XLOOKUP to search from the last item to the first, returning the most recent status.
XLOOKUP provides a robust and flexible solution for a wide array of lookup challenges in Excel, simplifying complex data retrieval tasks. For more in-depth information, you can explore resources like the Microsoft Office Support page on XLOOKUP.