Lookup & Reference
XLOOKUP across two identifier columns: OR matches and precedence
Normalize dual-column matches and choose between first matching row and primary-column priority.
Beware the classic Boolean OR trap: TRUE + TRUE = 2, which misses XLOOKUP(1, ...)!
Adding two Boolean comparisons produces 0, 1 or 2. Normalize the sum to a Boolean with >0, then convert to 1/0 before looking up 1; otherwise a row matching both identifier columns can be skipped.
OR lookup chooses the first matching row in source order, regardless of which identifier column matched. The nested lookup instead searches the entire primary column before falling back to the alias column. These policies can return different records if a code appears in multiple rows; neither establishes that identifiers are unique.
Store identifiers consistently as text, especially barcodes with leading zeroes. This example rejects empty queries and numeric query values. Exact lookup is case-insensitive; wildcard characters in the query are literal. Prices are required to be numeric in all four rows, so an empty price is not silently displayed as zero.
For the leading-zero experiment, enter ="0010" in the code and query cells so their evaluated values remain text rather than being parsed as the number 10.
| SKU (A) | UPC / Alias (B) | Price (C) | Search Input E2 Behavior |
|---|---|---|---|
| SKU-10 | UPC-881 | $45 | Matches either "SKU-10" or "UPC-881" |
| SKU-20 | UPC-992 | $92 | E2 = "UPC-992" -> 0 + 1 > 0 -> $92 |
| SKU-30 | SKU-30 (Same!) | $61 | E2 = "SKU-30" -> 1 + 1 = 2 > 0 -> 1 ($61 safe!) |
| SKU-40 | UPC-664 | $130 | E2 = "UPC-000" -> "Not Found" |
First matching row across either identifier column
A dual hit in one row becomes one match. Across different rows, the first match wins.
=IF(OR(COUNTBLANK(E2)>0,NOT(ISTEXT(E2)),COUNT(C2:C5)<>4),"Invalid inputs",XLOOKUP(1, --(((A2:A5 = E2) + (B2:B5 = E2)) > 0), C2:C5, "Not Found"))Chained XLOOKUP fallback alternative (searches Col A first, then Col B)
The primary SKU column takes precedence even when an alias matched an earlier row. Choose this only when that precedence matches the application rules.
=IF(OR(COUNTBLANK(E2)>0,NOT(ISTEXT(E2)),COUNT(C2:C5)<>4),"Invalid inputs",XLOOKUP(E2, A2:A5, C2:C5, XLOOKUP(E2, B2:B5, C2:C5, "Not Found")))Try the example
Use the original values or change them to test your understanding.