Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel XLOOKUP Syntax Made Simple for Everyday Lookups

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Concrete Example
  4. Advanced Usage
  5. Common Mistakes
  6. Tips
  7. Additional Section: Handling Errors
  8. Additional Section: Performance Tips
  9. Conclusion Section Not Allowed

XLOOKUP replaces VLOOKUP and HLOOKUP with a single function that can search in any direction and return an exact or approximate match. It works in Excel 365 and Excel 2021 and later. The basic syntax is LOOKUP_VALUE, LOOKUP_ARRAY, RETURN_ARRAY, and optional match and search mode arguments. This guide shows you how to build XLOOKUP with concrete examples and checks.

What You'll Need

  • A version of Excel that supports XLOOKUP (Excel 365 or Excel 2021 or newer)
  • A worksheet that contains the data you want to search
  • Clear headers for each column or row
  • Sample data to test the formula

Step-by-Step

  1. Identify the exact value you need to find. This is the lookup_value. For example, if you have a list of product codes and you need the price for code "ABC123", that code is the lookup_value.
  2. Select the range where Excel should search for that value. This is the lookup_array. If your product codes are in column A from A2 to A100, set lookup_array to A2:A100.
  3. Decide which column or row contains the data you want returned. This is the return_array. If prices are in column B from B2 to B100, set return_array to B2:B100.
  4. Enter the formula: =XLOOKUP(lookup_value, lookup_array, return_array). Using the example, the formula would be =XLOOKUP("ABC123", A2:A100, B2:B100).
  5. Optional: Add a fourth argument to control match mode. Use 0 for an exact match, -1 for exact or next smaller item, 1 for exact or next larger item, and 2 for wildcard match. For most cases, keep it at 0.
  6. Optional: Add a fifth argument to control search direction. Use 1 for first-to-last search (default) or -1 for last-to-first search. Use -1 when you need to find the last occurrence of a duplicate value.
  7. Press Enter. Excel will return the corresponding value from the return_array. In the example, it will display the price associated with product code "ABC123".
  8. Test the formula with several different lookup values to ensure it works across your data set.
  9. If you need to look left, you can either rearrange your data so the lookup column is to the left of the return column, or use a negative search mode by setting the fifth argument to -1. This allows XLOOKUP to search from the bottom up.
  10. Combine XLOOKUP with IFERROR to handle cases where the value is not found. For example: =IFERROR(XLOOKUP("ABC123", A2:A100, B2:B100), "Not found"). This prevents the #N/A error from appearing.
  11. When copying the formula to other cells, lock the ranges with absolute references if you do not want them to shift. Use dollar signs: =XLOOKUP($D2, $A$2:$A$100, $B$2:$B$100).

Concrete Example

Suppose you have a table of sales figures where column A lists employee IDs, column B lists departments, and column C lists sales amounts. You want to find the sales amount for employee ID in cell E2. The steps are:

  1. Set lookup_value to E2.
  2. Set lookup_array to A2:A10 (the employee IDs).
  3. Set return_array to C2:C10 (the sales amounts).
  4. Enter =XLOOKUP(E2, A2:A10, C2:C10).
The formula returns the sales amount for the employee whose ID matches the value in E2. If you need to retrieve the department name instead, simply change the return_array to B2:B10.

Advanced Usage

XLOOKUP can also perform partial matches using wildcards. If you want to find any product code that starts with "AB", use a lookup_value like "AB*" and set the match mode to 2. Example: =XLOOKUP("AB*", A2:A100, B2:B100, "", 2). The second "" argument is the if_not_found placeholder, and the 2 at the end sets wildcard match.

When dealing with approximate matches, such as finding the appropriate tax bracket, use match mode -1 or 1. For instance, if tax rates increase at certain income thresholds, set match mode to -1 to find the next smaller threshold. Example: =XLOOKUP(income, lower_bounds, tax_rates, , -1). This returns the tax rate that corresponds to the highest threshold not exceeding the income.

Search mode can be useful when you have duplicate entries and need the last one. If you have a list of dates and want the most recent entry, set the fifth argument to -1. Example: =XLOOKUP(target_date, date_range, value_range, , , -1). This searches from the bottom of the range upward.

Common Mistakes

One frequent error is mismatching the size of lookup_array and return_array. Both must have the same number of rows or columns. If lookup_array has five rows and return_array has ten, Excel will return a #VALUE! error. Another mistake is forgetting to use absolute references when copying the formula, which causes the ranges to shift and point to the wrong data. Also, using text with leading or trailing spaces can cause mismatches; trim the data first with the TRIM function.

Using the wrong match mode can also lead to incorrect results. If you need an exact match but set match mode to 1, Excel may return the next larger item if an exact match is not found. Always verify the match mode matches the intended behavior.

Tips

When working with large tables, name your ranges for readability. Select the column of product codes, go to the Name Box, and type "ProductCodes". Then use =XLOOKUP(E2, ProductCodes, Prices). This makes formulas easier to understand.

Combine XLOOKUP with other functions for more complex lookups. For example, to retrieve a value only if a condition is met, use =IF(condition, XLOOKUP(...), "No match"). This allows conditional logic around the lookup.

If you need to return multiple columns based on a single lookup, you can nest XLOOKUP or use FILTER. Example: =FILTER(Price_Column, (Employee_ID_Column = lookup_value) * (Department_Column = condition)). This returns all matching prices that also meet the department condition.

When using wildcards, remember that * matches any sequence of characters and ? matches any single character. You can combine them, such as "A?C*" to match any string that starts with A, any single character, then C.

Additional Section: Handling Errors

Errors are common when the lookup_value is not found. Use IFERROR to trap the #N/A error and replace it with a custom message. Example: =IFERROR(XLOOKUP(E2, A2:A100, B2:B100), "Lookup failed"). This improves readability for users.

If you receive a #REF! error, check that the return_array reference is still valid after any insertions or deletions in the worksheet. Adjust the range accordingly.

When dealing with circular references, ensure that the formula does not depend on its own result. XLOOKUP itself does not cause circular references, but if you nest it with other functions that reference the same cells, you may create a loop.

Additional Section: Performance Tips

XLOOKUP is generally faster than VLOOKUP because it does not require the lookup column to be the leftmost column and can search in any direction. However, performance can still be impacted by large data sets. To improve speed, limit the range of lookup_array and return_array to only the necessary cells rather than entire columns.

Using whole-column references (e.g., A:A) can slow down calculation, especially in large workbooks. Define a specific range like A2:A5000 instead. This reduces the amount of data Excel must scan for each lookup.

If you have multiple lookups that use the same lookup_array, consider storing that range in a named range. This avoids repeating the same reference and can make the workbook easier to maintain.

Conclusion Section Not Allowed

Do not add a concluding paragraph that summarizes the article. Continue with the next required section if needed, but do not provide a summary or closing statement.