Sub topic 8
Approximate match for tiers and bands
This chapter assumes you can write a basic XLOOKUP with an exact match and a custom if_not_found message. It also assumes you know absolute references such as $E$2, and that you have Excel for Microsoft 365, Excel 2021 or later, or Excel for the web.
Many lookups have no exact entry to find. A score of 85 is not in a grade table, and a sales total of 31,250 is not in a commission table. You want the band the value falls into. XLOOKUP does this through the match_mode argument.
What approximate match means
Approximate match means "find the closest entry in a direction" instead of "find an identical entry". XLOOKUP supports two directions:
| match_mode | Behavior | Typical table |
|---|---|---|
| 0 | Exact match only (default) | IDs, names, codes |
| -1 | Exact match, otherwise the next smaller item | Tables of lower bounds |
| 1 | Exact match, otherwise the next larger item | Tables of upper limits |
In both modes, an exact match wins if one exists. The "next smaller" or "next larger" rule applies only when no exact match is found.
Next smaller: tables of lower bounds
A grade table usually lists the lowest score for each grade. Put the bounds in E2:E6 and the grades in F2:F6:
| E (minimum score) | F (grade) |
|---|---|
| 0 | F |
| 60 | D |
| 70 | C |
| 80 | B |
| 90 | A |
With the student's score in B2, use match_mode -1:
=XLOOKUP(B2, $E$2:$E$6, $F$2:$F$6, "Below minimum", -1)For a score of 85, no row equals 85. XLOOKUP looks for the largest bound that is less than or equal to 85. That bound is 80, so the formula returns B.
Boundary values
Because exact matches win, a score of exactly 90 returns A, and a score of 89.99 returns B. Decimal scores work the same way. This is why lower-bound tables pair naturally with -1: each bound belongs to the band that starts at that bound.
Values below the smallest bound
If the lowest bound were 50 instead of 0, a score of 40 would have no smaller entry. XLOOKUP then returns the if_not_found value, or #N/A if you omitted it. The fourth argument is how you show "Below minimum" instead of an error. Including a bound of 0 in the table is a simple way to cover every non-negative score.
Next larger: tables of upper limits
Some tables list the top of each band instead. A courier might charge by maximum parcel weight:
| E (max weight, kg) | F (price) |
|---|---|
| 1 | 5.00 |
| 5 | 9.00 |
| 10 | 14.00 |
| 20 | 22.00 |
A 3 kg parcel fits in the "up to 5 kg" band. Use match_mode 1:
=XLOOKUP(B2, $E$2:$E$5, $F$2:$F$5, "Above range", 1)XLOOKUP looks for the smallest limit that is greater than or equal to 3. That limit is 5, so the formula returns 9.00. A parcel of exactly 5 kg also returns 9.00, because the exact match wins. A 25 kg parcel has no larger limit, so the result is "Above range".
Choosing between -1 and 1
Read how the table's first column is defined:
- If each number is where a band starts ("60 and above"), use -1.
- If each number is where a band ends ("up to 5"), use 1.
Using the wrong mode does not produce an error. It returns a plausible but wrong value. For example, applying mode -1 to the weight table above gives a 3 kg parcel the 1 kg price of 5.00. Always test a value that sits between two entries and one that sits exactly on an entry.
A worked example: commission rates
A company pays commission at a rate set by the sales total. The rate applies to the whole amount, not just the part above each threshold.
| E (sales from) | F (rate) |
|---|---|
| 0 | 2% |
| 10000 | 4% |
| 25000 | 6% |
| 50000 | 8% |
To get the rate for the sales figure in B2:
=XLOOKUP(B2, $E$2:$E$5, $F$2:$F$5, 0, -1)To get the commission amount, multiply by the sales figure:
=B2 * XLOOKUP(B2, $E$2:$E$5, $F$2:$F$5, 0, -1)For sales of 31,250, the lookup returns 6%, and the commission is 1,875. A sales figure of 50,000 returns 8%, because the exact match wins.
Notice that the formula supplies 0 for if_not_found. This table starts at 0, so only a negative figure, such as a net refund, would miss. Returning 0 means such a row earns no commission instead of showing an error that spreads into totals. Choose the fallback deliberately. A silent 0 can hide bad data, so use text like "Check input" if you would rather see the problem.
If your commission is marginal, where each rate applies only to the slice within its band, a single XLOOKUP is not enough. You would need to calculate each band's slice separately, for example with SUMPRODUCT.
Sorting and performance
The default search_mode is 1, which searches from the first item to the last. In that mode XLOOKUP checks the whole lookup array and picks the best candidate, so the table does not have to be sorted. This is a real difference from VLOOKUP(..., TRUE), which silently returns wrong answers on unsorted data.
Sorted tables are still good practice for readability. They also let you switch to binary search later (search_mode 2) on very large tables, a topic covered in its own chapter.
Edge cases and gotchas
Numbers stored as text
If the lookup value is the number 85 but the bounds in column E are text such as "80", the types differ and the match fails. In approximate mode, text and numbers are not compared with each other, so you typically get #N/A or your fallback message. Signs of text numbers include left alignment and a small green triangle. Convert them with Text to Columns, or multiply the column by 1. The earlier chapter on data-type pitfalls covers this in more detail.
Duplicate bounds
If two rows have the same bound, XLOOKUP returns the first one it meets in the search direction. Duplicated bounds are almost always a data entry mistake, so remove them.
Gaps and overlaps
Approximate matching ignores the idea of a band's upper edge. A band runs from its bound up to just before the next bound. If your business rules say "60 to 69.5 is D and 69.5 to 70 is unclassified", the table cannot express that. Add a row to represent the gap instead.
Blank lookup cells
A blank cell is treated as 0. In a table that starts at 0, a blank score therefore returns "F", which is misleading. Guard against it:
=IF(B2="", "", XLOOKUP(B2, $E$2:$E$6, $F$2:$F$6, "Below minimum", -1))Relative references when copying down
If you copy a formula down a column, anchor the table with $, as in $E$2:$E$6. Without it the table range shifts one row per copy. Rows near the bottom then search a truncated or empty range and return fallback values.
Text lookups
Approximate modes also compare text alphabetically, but this is rarely what you want. For partial text matching, use wildcards instead. Those are covered in a later chapter.
Troubleshooting checklist
- Is the result a wrong band, not an error? Check that you chose -1 or 1 to match how the table's numbers are defined.
- Is the result
#N/Aor your fallback for a value that should match? Check for numbers stored as text, and check that the value is not below the smallest bound or above the largest limit. - Does the result change when you copy the formula? Check absolute references.
- Does the top row return "F" for blank inputs? Add a blank check.
Exercise
A tax table has these lower bounds in E2:E4: 0, 20000 and 50000. The matching rates in F2:F4 are 10%, 20% and 30%. Write a formula that returns the rate for the income in B2, and say what it returns for an income of 20000 and an income of 35000. Use "Invalid" when no band applies.
Show answer
=XLOOKUP(B2, $E$2:$E$4, $F$2:$F$4, "Invalid", -1). An income of 20000 matches the bound 20000 exactly and returns 20%. An income of 35000 has no exact match, so XLOOKUP uses the next smaller bound, 20000, and returns 20%. A negative income would return "Invalid".
Exercise
A delivery table lists maximum distances in E2:E5 as 10, 25, 50 and 100 km, with fees in F2:F5. Which match_mode should you use to find the fee for a 30 km delivery, which entry does XLOOKUP pick, and what happens for 120 km if the fourth argument is "Out of area"?
Show answer
Use match_mode 1, because the table lists upper limits. For 30 km there is no exact match, so XLOOKUP picks the smallest limit that is greater than or equal to 30, which is 50, and returns that row's fee. For 120 km no larger limit exists, so the formula returns "Out of area".
Exercise
Your grade formula returns #N/A for a score of 85 even though the table has a bound of 80. The scores were pasted from another system. What is the most likely cause, and how can you confirm and fix it?
Show answer
The scores are probably stored as text, so 85 does not compare with the numeric bounds. Confirm by checking for left alignment or a green triangle, or by testing =ISNUMBER(B2), which returns FALSE. Fix it by converting the column to numbers, for example with Text to Columns or by multiplying the values by 1.