Sub topic 3
Exact match: the default behavior
This chapter assumes you can enter and copy formulas, you understand ranges and absolute references such as $A$2:$A$10, and you use Excel for Microsoft 365, Excel 2021 or later, or Excel for the web.
What "exact" means
When you leave out the fifth argument, match_mode, XLOOKUP uses the value 0. That value means exact match. XLOOKUP returns a result only when a cell in the lookup array equals the lookup value. If no cell is equal, it does not guess a nearby value. It returns the #N/A error.
The simplest form uses three arguments:
=XLOOKUP(E2, A2:A10, C2:C10)E2is the lookup value, the thing you are searching for.A2:A10is the lookup array, the range that is searched.C2:C10is the return array, the range the answer comes from.
XLOOKUP finds the position of the match in the lookup array. It then returns the item at that same position in the return array.
A worked example
Suppose this product list sits in A1:C6, and you type a product code in E2.
| Row | A | B | C |
|---|---|---|---|
| 1 | Code | Product | Price |
| 2 | P-100 | Keyboard | 25 |
| 3 | P-200 | Mouse | 12 |
| 4 | P-300 | Monitor | 140 |
| 5 | P-400 | Webcam | 45 |
| 6 | P-500 | Headset | 60 |
To get the price for the code in E2, use this formula:
=XLOOKUP(E2, A2:A6, C2:C6)If E2 contains P-300, the match is the third item in A2:A6. XLOOKUP returns the third item in C2:C6, which is 140. To get the product name instead, change only the return array to B2:B6.
flowchart TDBehaviors to know
Exact matching has a few properties that affect your results.
- The data does not need to be sorted. The default search checks items one at a time, so the order of the list does not matter.
- Case is ignored.
p-300matchesP-300. - The first match wins. If the lookup value appears more than once, XLOOKUP returns the result for the first occurrence, searching from the top. Chapter 10 covers how to change the direction.
- The two ranges must be the same size. The lookup array and return array must have the same number of rows (for a column) or columns (for a row). Otherwise the formula returns
#VALUE!. - Wildcards are not active. With
match_mode0, a*or?in your lookup value is treated as an ordinary character.
Locking ranges when you copy the formula
If you copy the formula down a column of lookup values, the ranges must stay fixed. Add absolute references to both arrays:
=XLOOKUP(E2, $A$2:$A$6, $C$2:$C$6)Without the dollar signs, each copied row shifts the ranges down by one. The lookup then searches the wrong cells, and later rows fail with #N/A even though the code exists in the list.
Why a match can fail
The most common cause of an unexpected #N/A is that two values look the same but are not equal. For example, P-300 with a trailing space does not equal P-300. A number stored as text, such as "300", does not equal the number 300. Chapter 5 covers these data-type problems in detail. For now, remember that exact means exactly equal.
Exercise
Using the product table above, write a formula that returns the product name for the code in E2. Make it safe to copy down a column. What does it return if E2 contains P-999?
Show answer
=XLOOKUP(E2, $A$2:$A$6, $B$2:$B$6). The code P-999 is not in A2:A6, and the default match_mode 0 allows only exact matches, so the formula returns #N/A.