Sub topic 7
Match modes: exact, nearest, and wildcard
Assume you know how to enter formulas in Google Sheets and use cell, range, and absolute references. This chapter focuses on the match_mode argument in XLOOKUP and the final argument in VLOOKUP.
A lookup compares a search key with values in a lookup range. The match mode tells Sheets what counts as a match when it cannot find the key exactly.
flowchart TD
A[Search key] --> B{Match mode}
B -->|Exact| C[Return only an equal key]
B -->|Next smaller| D[Return the largest key below the search key]
B -->|Next larger| E[Return the smallest key above the search key]
B -->|Wildcard| F[Match a text pattern]Exact matching
Exact matching returns a result only when the lookup key equals a value in the lookup range.
With VLOOKUP, use FALSE as the last argument:
=VLOOKUP("P-102", A2:C100, 3, FALSE)This searches the first column of A2:C100 for P-102 and returns the value from the third column. If P-102 is missing, the formula returns #N/A.
XLOOKUP uses exact matching by default. You can also write the match mode explicitly as 0:
=XLOOKUP("P-102", A2:A100, C2:C100, "Not found", 0)The fifth argument, 0, means exact match. The fourth argument supplies a readable result when no exact match exists.
Next smaller and next larger matches
Some data uses ranges or tiers instead of individual keys. Consider this table:
| Minimum points | Level |
|---|---|
| 0 | Basic |
| 100 | Standard |
| 500 | Plus |
| 1000 | Premium |
If B2 contains 620, the correct level is Plus. The formula must find the largest minimum that is less than or equal to 620.
Use XLOOKUP match mode -1 for an exact match or the next smaller value:
=XLOOKUP(B2, $F$2:$F$5, $G$2:$G$5, "Below minimum", -1)For 620, this returns Plus. Match mode -1 is useful for thresholds, price bands, shipping limits, and score tiers.
Use match mode 1 for an exact match or the next larger value:
=XLOOKUP(B2, $F$2:$F$5, $G$2:$G$5, "Above maximum", 1)This is useful when each key represents an upper limit rather than a minimum.
The words “next smaller” and “next larger” describe the key values, not the result text. For a search key of 620, the next smaller key is 500, and the next larger key is 1000.
VLOOKUP approximate matching
For VLOOKUP, TRUE requests approximate matching:
=VLOOKUP(B2, $F$2:$G$5, 2, TRUE)This returns the row with the largest first-column value less than or equal to B2. The first column must be sorted in ascending order. If it is not sorted, the formula can return an incorrect result without an obvious error.
Wildcard matching
XLOOKUP match mode 2 treats special characters in the search key as wildcards:
*matches any number of characters.?matches exactly one character.
This formula finds the first product name beginning with Wid:
=XLOOKUP("Wid*", B2:B100, A2:A100, "Not found", 2)The formula searches B2:B100 and returns the matching value from A2:A100. It could match Widget, Widow, or Wide screen.
Use a wildcard when the full text varies but part of it is known. Use exact matching when the key identifies one specific record.
Exercise
Which XLOOKUP match mode should you use to find the level for 750 points in a table of minimum point thresholds?
Show answer
Use match mode -1, because it returns an exact threshold or the next smaller threshold.