Sub topic 9
XLOOKUP options for missing keys and match modes
This chapter assumes you know basic Excel formulas, relative and absolute references, and the difference between a model input and a calculated output. You also need a simple assumptions table with unique keys.
Handling a missing key
XLOOKUP searches a lookup array for a value and returns the corresponding value from a return array. Its fourth argument controls what happens when no match exists.
Suppose Assumptions contains keys in column B and values in column C. The key to find is in A5.
=XLOOKUP($A5, Assumptions!$B$3:$B$12, Assumptions!$C$3:$C$12, "Missing assumption")If the key exists, Excel returns its value. If it does not exist, Excel returns Missing assumption instead of #N/A.
A visible message is useful during model review. It prevents a missing input from looking like a valid zero or blank. You can also return a numeric fallback, but use that only when zero has a clear business meaning.
=XLOOKUP($A5, Assumptions!$B$3:$B$12, Assumptions!$C$3:$C$12, 0)Choosing the match mode
The fifth argument controls how Excel matches the lookup value.
| Match mode | Meaning | Typical use |
|---|---|---|
| `0` | Exact match, the default | Account, assumption, or entity key |
| `-1` | Exact match or next smaller item | Tier thresholds |
| `1` | Exact match or next larger item | Less common threshold designs |
| `2` | Wildcard match | Text patterns |
For financial model keys, keep the default exact match or specify 0 explicitly. Approximate matching can return a plausible but incorrect value when a key is misspelled.
The wildcard mode supports * for any number of characters and ? for one character. For example, this formula finds the first assumption whose key starts with Opex.
=XLOOKUP("Opex*", Assumptions!$B$3:$B$12, Assumptions!$C$3:$C$12, "Missing assumption", 2)Wildcard lookup is useful for controlled text patterns, but it is risky when several rows can match. XLOOKUP returns only the first matching result.
Approximate matching for tiers
Approximate matching is appropriate when the lookup array contains ordered thresholds. Assume Tiers!B3:B7 contains 0, 100000, 250000, 500000, and 1000000, while Tiers!C3:C7 contains the corresponding rates.
=XLOOKUP(B5, Tiers!$B$3:$B$7, Tiers!$C$3:$C$7, "No tier", -1)With match mode -1, Excel returns the rate for the largest threshold less than or equal to B5. The threshold list must be sorted in ascending order. If it is not sorted, the result may be wrong without producing an obvious error.
The sixth argument controls search order. The default searches from first to last. Use -1 to search from last to first when duplicate matches exist and the last matching row should win. This should be a deliberate rule, not a way to hide duplicate keys.
flowchart TD
A[Lookup key] --> B{Exact key found?}
B -->|Yes| C[Return matching value]
B -->|No| D[Return not-found message]
C --> E[Check key uniqueness]
D --> F[Investigate missing assumption]Checks before trusting the result
A lookup should have an integrity check beside it. Count the key in the assumptions list:
=COUNTIF(Assumptions!$B$3:$B$12, $A5)A result of 1 means one match exists. 0 means the key is missing. A result greater than 1 means the key is duplicated, so the returned value depends on search order.
Exercise
Which XLOOKUP match mode should you use to retrieve an assumption by a unique account name, and how should you handle a missing account?
Show answer
Use exact matching, mode 0 or the default, and provide a clear fourth argument such as "Missing assumption". Check the key with COUNTIF to detect missing or duplicated entries.