Function Problems

How to Use XLOOKUP with Two Alternative Search Fields in Excel & WPS

John WilsonJohn Wilson Nov 10, 2026 869 views

Question details

The user needs to dynamically retrieve data using XLOOKUP when the search criteria can come from one of two alternative input fields.

How to Use XLOOKUP with Two Alternative Search Fields
Product
Spreadsheet
Device & OS
not provided
Scenario
Building a lookup interface where users can search by either a primary identifier (like a Part Number) or a secondary identifier (like an Old Number), ensuring the formula automatically searches the correct column based on the populated input.
Observed behavior
Using separate standard XLOOKUP formulas for each field causes conflicting results, searches the wrong column, or displays outdated lookup information when input cells are changed.
Before you start

Ensure that all identifiers in your lookup arrays and input cells have consistent data types, as mixing numbers formatted as text with standard numbers will result in #N/A errors.

Solution 1Recommended

Use the LET Function to Dynamically Switch XLOOKUP Inputs

The LET function allows you to define variables for the active search value and lookup column, ensuring XLOOKUP only processes the field that contains data.

By nesting an IF function within LET, you can evaluate which input cell is currently populated and dynamically assign both the search value and the corresponding search column. This completely prevents formula conflicts and keeps your workbook calculation efficient.

1
Select the output cell

Click on the cell where you want the final XLOOKUP result to be displayed.

2
Input the LET and IF structure

Type the foundation of the formula: =LET(value, IF(H9<>"", H9, H7), column, IF(H9<>"", A2:A10606, C2:C10606), XLOOKUP(value, column, B2:B10606, "")).

3
Customize your cell references

Replace H9 and H7 with your actual alternative input cells. Replace A2:A10606 with the search column for the first input, C2:C10606 with the search column for the second, and B2:B10606 with the column containing the data you want to return.

4
Apply data validation

To prevent users from filling both fields, go to the Data tab, select Data Validation, and apply a Custom formula like =COUNTA($H$7,$H$9)<=1 to the input cells.

Use the LET Function to Dynamically Switch XLOOKUP Inputs
Best Practice: Standardize all part numbers as either pure text or pure numbers before applying the XLOOKUP function to ensure flawless matching.
Advanced Spreadsheet Functions

Master Complex Lookups in WPS Spreadsheet

WPS Spreadsheet fully supports advanced functions like XLOOKUP, LET, and nested logical formulas, allowing you to build dynamic, professional-grade search queries with ease.

  1. 1. Open your dataset: Launch WPS Spreadsheet and open the workbook containing your alternative search fields.
  2. 2. Access the Function Wizard: Select your target output cell and click the 'fx' (Insert Function) icon next to the formula bar.
  3. 3. Search for your function: Type XLOOKUP or LET in the search box to access the built-in wizard, which guides you through each parameter step-by-step.
  4. 4. Calculate and verify: Enter your cell references as prompted by the wizard, click OK, and test your alternative search fields to verify the output.
100% compatibility with Microsoft Excel formulas, ensuring your XLOOKUP and LET functions work seamlessly.Intuitive interface and color-coded formula builder to help manage complex nested functions.Built-in error checking to quickly debug mismatched data types or referencing issues.Free, lightweight alternative to heavy data processing software with cross-platform support.
microsoft office alternative - wps office

Frequently Asked Questions

Why does my XLOOKUP return #N/A even when the value visually exists in the column?

This error typically occurs due to mismatched data types. For example, if your lookup input is stored as a number, but the values in your lookup array are formatted as text, XLOOKUP will not recognize them as a match. Standardizing the formatting across both fields resolves this issue.

What happens if a user accidentally fills both alternative search fields?

In the IF and LET structures provided, the formula evaluates conditions from left to right. It will process the first true condition (e.g., the H9 cell) and ignore the secondary cell (H7). To prevent user confusion, it is recommended to add Data Validation rules restricting input to only one field.

Can I search across three or more alternative fields using this method?

Yes. You can expand the LET function by nesting additional IF statements within the variable definitions, or use multiple nested IF formulas, evaluating each potential input cell sequentially until a populated one is found.