Sub topic 11
Chaining fallback lookups
This chapter assumes you can enter and copy formulas, use absolute references such as $A$2:$B$100, and write a basic VLOOKUP. You should also know what IFNA does. It returns a value you choose when its first argument is #N/A, and it passes every other result through unchanged.
The problem: one list is not enough
Real data is often split across several lists. Customer prices might sit in a current price list on Sheet1 and in an archive on Sheet2. A single VLOOKUP returns #N/A for any code that is not in the list it searches. You want the formula to try the second list before it gives up.
How the chain works
IFNA(value, value_if_na) evaluates value first. If the result is #N/A, it evaluates and returns value_if_na. The fallback can itself be another IFNA that contains a second lookup. Excel works through the lookups from the inside out of your reading order. It tries the first, and only on #N/A does it try the next.
=IFNA(VLOOKUP(E2, Sheet1!$A$2:$B$100, 2, FALSE), IFNA(VLOOKUP(E2, Sheet2!$A$2:$B$100, 2, FALSE), "Not found"))Read it in three parts:
- The first lookup searches
Sheet1. If it finds the code, that price is the result and nothing else runs. - If the first lookup returns
#N/A, the innerIFNAruns the lookup onSheet2. - If both lookups return
#N/A, the text"Not found"is returned.
Why IFNA and not IFERROR
Swapping IFNA for IFERROR in the chain makes it run, but it changes what is allowed to fall through. Suppose someone deletes the Sheet1 price list. The first lookup now returns #REF!. With IFNA, the #REF! is not caught, so it appears in the cell and you notice the damage. With IFERROR, the formula quietly moves on to Sheet2 and may return an old price that looks plausible.
A chain has several places where a real fault can hide, one per lookup. Using IFNA at every level keeps the fallback limited to "not found in this list".
Adding a third list
Each extra list adds one more nested IFNA. The final argument of the outermost level is the last-resort message.
=IFNA(VLOOKUP(E2, Sheet1!$A$2:$B$100, 2, FALSE), IFNA(VLOOKUP(E2, Sheet2!$A$2:$B$100, 2, FALSE), IFNA(VLOOKUP(E2, Sheet3!$A$2:$B$100, 2, FALSE), "Not found")))This still works, but it is getting hard to read and edit. Every list needs matching brackets and an identical lookup, and a typo in one range is easy to miss. Past three lists, consider combining the data into one table instead.
The same chain with XLOOKUP
XLOOKUP has a built-in if_not_found argument, so you can put the second lookup there. No wrapper function is needed.
=XLOOKUP(E2, Sheet1!$A$2:$A$100, Sheet1!$B$2:$B$100, XLOOKUP(E2, Sheet2!$A$2:$A$100, Sheet2!$B$2:$B$100, "Not found"))Like IFNA, if_not_found reacts only to a missing match. A #REF! from a broken range still shows.
Checking your chain
Test each path separately rather than only the happy case.
| Test value in E2 | Where it exists | Expected result |
|---|---|---|
| A code in the current list | `Sheet1` | The `Sheet1` price |
| A code only in the archive | `Sheet2` | The `Sheet2` price |
| A code in neither list | Nowhere | `Not found` |
| A code in both lists | `Sheet1` and `Sheet2` | The `Sheet1` price, because the first list wins |
The last row shows a design decision. The order of the lookups sets priority, so put the most trustworthy list first.
Common mistakes
- Mismatched ranges. The lookup column and result column must line up in each list. Copy the first lookup and change only the sheet name.
- Forgetting
FALSE. Without it,VLOOKUPuses approximate matching and may return a wrong price instead of#N/A, so the chain never reaches the next list. - Relative references. Without
$, the ranges shift when you fill the formula down, and lookups begin to miss. - Using
IFERRORout of habit. It hides#REF!,#NAME?and#VALUE!along with#N/A.
Exercise
Column A on Active holds product codes and column B holds prices. Retired has the same layout. Write a formula for E2 that returns the price from Active, then from Retired, and otherwise the text "Unknown". It should show a #REF! if either range is broken.
Show answer
=IFNA(VLOOKUP(E2, Active!$A$2:$B$100, 2, FALSE), IFNA(VLOOKUP(E2, Retired!$A$2:$B$100, 2, FALSE), "Unknown")). IFNA catches only #N/A, so a #REF! from a broken range is not replaced, and each lookup uses FALSE for exact matching.