How to Look Up a Value from Two Possible Columns in Excel
Question details
The user needs a formula to look up a corresponding value from a mapping worksheet when the search key could be located in either of two possible columns.

- Product
- Excel and WPS Spreadsheet
- Device & OS
- not provided
- Scenario
- Data mapping and lookup where the exact column containing the lookup value is uncertain.
- Observed behavior
- Standard lookup functions only search one specific column, returning an error if the value is located in the alternative column.
Verify that your mapping worksheet contains clear, distinct columns for the lookup keys and return values, and ensure your spreadsheet software supports the XLOOKUP function.
Use a Combined IFERROR and XLOOKUP Formula
This approach attempts to find the value in the first column, and if it results in an error, automatically falls back to searching the second column.
By nesting an XLOOKUP function inside an IFERROR function, you can instruct the spreadsheet to check a primary column first. If the lookup value is not found there, IFERROR triggers the second XLOOKUP to check the secondary column.
Click on the cell where you want the mapped region or corresponding value to appear.
Type the formula: =IFERROR(XLOOKUP(F2,Map!A:A,Map!B:B), XLOOKUP(G2,Map!A:A,Map!B:B,"")). Adjust 'F2' and 'G2' to match your possible input cells, and 'Map!A:A' and 'Map!B:B' to match your actual mapping worksheet and column ranges.
Press Enter to execute the formula. Then, click and drag the fill handle at the bottom right corner of the cell down to apply it to the rest of the column.

Effortlessly Manage Complex Lookups with WPS Spreadsheet
WPS Spreadsheet provides robust, built-in support for advanced functions like XLOOKUP and IFERROR, allowing you to seamlessly map and look up data across multiple columns without compatibility issues.
- 1. Open your dataset in WPS: Launch WPS Office and open your .xlsx file containing the data and mapping worksheets.
- 2. Insert the primary lookup: Select your output cell and start typing the IFERROR and XLOOKUP formula to target your first potential column.
- 3. Add the secondary lookup: Complete the formula by inserting the second XLOOKUP as the fallback condition within the IFERROR function.
- 4. Populate the column: Press Enter, then double-click the fill handle to automatically map the values for all remaining rows.

Frequently Asked Questions
Can I look up a value across more than two columns?
Yes, you can nest multiple IFERROR functions to check three or more columns. For example: =IFERROR(XLOOKUP(F2,...), IFERROR(XLOOKUP(G2,...), XLOOKUP(H2,...))).
Why does my formula return a #REF! error?
A #REF! error typically occurs if the worksheet referenced in the formula (such as 'Map!') has been deleted or renamed, or if the column ranges are invalid. Ensure the sheet name in your formula exactly matches the actual tab name at the bottom of your workbook.
What does the "" at the end of the XLOOKUP formula do?
The empty double quotes "" serve as the 'if_not_found' argument for the second XLOOKUP. If the value is found in neither the first nor the second column, the formula will return a blank cell instead of an ugly #N/A error.




