XLOOKUP is a powerful function in Microsoft Excel that searches a range or an array and returns an item corresponding to the first match it finds. It’s a more flexible and powerful alternative to older lookup functions like VLOOKUP and HLOOKUP. Here are some key aspects and examples of how to use XLOOKUP:
Syntax
XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])
- lookup_value: The value you want to search for.
- lookup_array: The range or array to search within.
- return_array: The range or array that contains the value to return.
- if_not_found (optional): The value to return if no match is found.
- match_mode (optional): The type of match (default is 0 for exact match).
- 0: Exact match.
- 1: Exact match or next larger item.
- -1: Exact match or next smaller item.
- 2: A wildcard match where * matches any number of characters.
- search_mode (optional): The order to search (default is 1 for searching from first to last).
- 1: Search from first to last.
- -1: Search from last to first.
- 2: Binary search (sorted ascending order).
- -2: Binary search (sorted descending order).
Example
Suppose you have a list of products and their prices, and you want to find the price of a specific product.
ABProductPriceApple1.20Banana0.50Cherry2.00Date1.50
You want to find the price of “Cherry.”
=XLOOKUP(“Cherry”, A2:A5, B2:B5)
This formula searches for “Cherry” in the range A2
and returns the corresponding value from the range B2, which is 2.00.Advanced Example with Optional Arguments
Suppose you want to search for a product that might not be in the list and return a custom message if it’s not found.
=XLOOKUP(“Orange”, A2:A5, B2:B5, “Product not found”)
If “Orange” is not found in the list, the function will return “Product not found.”
Benefits of XLOOKUP over VLOOKUP and HLOOKUP
- No Column/Row Index Needed: Unlike VLOOKUP and HLOOKUP, you don’t need to specify the column/row index number for the return value.
- Works Both Ways: XLOOKUP can look both vertically (like VLOOKUP) and horizontally (like HLOOKUP).
- Exact Match by Default: XLOOKUP defaults to an exact match, reducing the risk of errors.
- Simplified Syntax: The syntax is more intuitive and easier to use for complex lookups.
- Handles Missing Data: The [if_not_found] argument makes it easy to handle cases where the lookup value is not found.
Practical Uses
- Dynamic Data Retrieval: Fetching dynamic data from tables where the structure might change.
- Error Handling: Providing custom messages or alternative values when a lookup fails.
- Complex Criteria Matching: Using advanced match modes and search modes for more sophisticated lookup scenarios.
XLOOKUP is a versatile tool that enhances the ability to manage and analyze data in Excel, making it a valuable function for both basic and advanced users.