Sub topic 1
What a Lookup Does and Why XLOOKUP
Prerequisites
This chapter assumes you can already do the following:
- Enter a formula in a cell and copy it down a column.
- Read cell references and ranges such as
A2:A10, and tell relative references (E2) from absolute ones ($E$2). - Open a version of Excel that includes XLOOKUP. That means Excel for Microsoft 365, Excel 2021 or later, or Excel for the web. Excel 2019 and earlier do not have it.
You don't need any experience with VLOOKUP, HLOOKUP, INDEX or MATCH. If you have used them, the comparisons later in this chapter will be more useful to you.
What a lookup does
A lookup takes a value you already have and uses it to find related information somewhere else. You supply a key, such as a product ID, an employee number or a test score. The lookup searches a list for that key and returns something stored beside it, such as a price, a department or a letter grade.
Most spreadsheet work includes this step. Typical cases are:
- An order sheet stores product IDs. A separate price list stores the price for each ID. A lookup brings the price into the order sheet.
- A payroll sheet stores employee numbers. A lookup retrieves each person's name or manager.
- A gradebook stores numeric scores. A lookup converts each score into a letter grade by finding which band it falls in.
Doing this by hand means scanning a list with your eyes, which is slow and error-prone. A lookup formula does it consistently, and it updates when the source data changes.
Every lookup has the same four parts:
- The lookup value is the key you are searching for.
- The lookup range is the list that holds the keys.
- The return range is the list that holds the answers.
- The match rule decides what counts as a match: an identical value, the nearest smaller value, or text that fits a pattern.
The two ranges must line up row by row. If the key is found in the third cell of the lookup range, the answer comes from the third cell of the return range.
A small data set
The examples in this chapter use a short price list. It sits in columns A to C, in rows 2 to 10, with headers in row 1.
| Row | A | B | C |
|---|---|---|---|
| 1 | ID | Product | Price |
| 2 | P101 | Notebook | 4.50 |
| 3 | P102 | Pen | 1.20 |
| 4 | P103 | Stapler | 8.75 |
| 5 | P104 | Folder | 0.90 |
| 6 | P105 | Marker | 2.10 |
| 7 | P106 | Tape | 3.40 |
| 8 | P107 | Scissors | 5.25 |
| 9 | P108 | Binder | 6.30 |
| 10 | P109 | Clips | 1.75 |
Cell E2 holds the ID you want to look up. For example, E2 contains P103.
Your first XLOOKUP
XLOOKUP is the lookup function built into modern Excel. In its simplest form it takes three arguments: what to find, where to look, and where to return from.
=XLOOKUP(E2, A2:A10, C2:C10)Read it as a sentence: find the value in E2 within A2:A10, and return the value from the same position in C2:C10. With P103 in E2, Excel finds it in the third cell of A2:A10. It returns the third cell of C2:C10, which is 8.75.
The formula uses exact matching by default. P103 matches only P103. It does not match P10 or P1030. Later chapters cover how to change this.
To return the product name instead of the price, change only the return range:
=XLOOKUP(E2, A2:A10, B2:B10)The lookup range and the return range are separate arguments. Changing what you retrieve means editing one argument, and you don't need to recount columns.
The six arguments at a glance
XLOOKUP accepts up to six arguments. The first three are required. The last three are optional and have defaults.
| Position | Name | Required | What it controls |
|---|---|---|---|
| 1 | lookup_value | Yes | The key to find |
| 2 | lookup_array | Yes | The range or array that is searched |
| 3 | return_array | Yes | The range or array the answer comes from |
| 4 | if_not_found | No | What to show when there is no match. The default is `#N/A`. |
| 5 | match_mode | No | Exact, next smaller, next larger, or wildcard. The default is exact (0). |
| 6 | search_mode | No | Search direction, or binary search. The default is first to last (1). |
You don't need to memorize this now. Each optional argument gets its own chapter. What matters here is that the function has a short required core and adds control only when you ask for it.
=XLOOKUP(E2, A2:A10, C2:C10, "Not found", 0, 1)This formula spells out every default except the not-found message. It behaves like the three-argument version for any ID that exists. For an ID that is missing, it shows Not found instead of #N/A.
Why XLOOKUP exists
Excel already had lookup tools before XLOOKUP, mainly VLOOKUP, HLOOKUP, and the INDEX and MATCH pair. XLOOKUP was added to remove the most common problems with them. Here is the same price lookup written with each approach.
=VLOOKUP(E2, A2:C10, 3, FALSE)
=INDEX(C2:C10, MATCH(E2, A2:A10, 0))
=XLOOKUP(E2, A2:A10, C2:C10)Problems with VLOOKUP that XLOOKUP avoids
- Column index numbers. VLOOKUP asks for a number (
3above) that says which column of the table to return. If someone inserts or deletes a column inside the table, the number can point at the wrong data without any error. XLOOKUP takes the return range itself, so Excel adjusts the reference automatically. - Approximate match by default. If you omit VLOOKUP's fourth argument, it assumes approximate matching, which needs sorted data and can silently return wrong rows. You must remember to type
FALSE. XLOOKUP defaults to exact matching. - Leftmost-column restriction. VLOOKUP can only search the first column of its table and return columns to the right. XLOOKUP's lookup and return ranges are independent, so the answer can sit to the left of the key.
- Verbose not-found handling. With VLOOKUP, a friendly message for missing values requires wrapping the formula in IFERROR. XLOOKUP has an argument for it.
Comparison with INDEX and MATCH
INDEX and MATCH solve most VLOOKUP problems. MATCH finds the position, and INDEX returns the value at that position. The cost is that you write and maintain two functions, and you must remember that the match type 0 means exact. XLOOKUP combines both steps into one function with a clearer argument order. INDEX and MATCH remain useful, and the final chapter in this tutorial compares them in more detail.
Capabilities VLOOKUP lacks
XLOOKUP can also:
- Search from the bottom of a list upward, which returns the last match instead of the first.
- Return several columns from one match by using a multi-column return range.
- Look up vertically or horizontally with the same function, so HLOOKUP is not needed.
- Match against wildcards, or return the next smaller or next larger item, with an explicit setting.
Compatibility
XLOOKUP is available in Excel for Microsoft 365, Excel 2021 and later, and Excel for the web. It is not available in Excel 2019, Excel 2016, or earlier perpetual-license versions. If you send a workbook containing XLOOKUP to someone with one of those versions, the formula cannot calculate for them. Excel shows it with a _xlfn. prefix, and the cell typically displays #NAME?.
Reading and checking a lookup formula
When a lookup gives a surprising result, check these points in order:
- Is the lookup value what you think it is? Click the cell and look at the formula bar.
- Do the lookup range and the return range have the same number of rows? A mismatch makes the formula fail with
#VALUE!. - Are the ranges anchored with
$if you copy the formula down? The lookup value should move down with each row (E2,E3, ...). The ranges should stay fixed ($A$2:$A$10).
=XLOOKUP(E2, $A$2:$A$10, $C$2:$C$10)Copied down from row 2, this formula keeps both ranges in place while E2 becomes E3, E4, and so on. This avoids one of the most common mistakes with lookups: ranges that drift as the formula is filled down, so some keys fall outside the searched area.
What comes next
The following chapters build on this foundation in the order shown below. Each one adds one idea to the basic three-argument formula.
Exercise
A price list has product IDs in A2:A10 and names in B2:B10. Prices are in C2:C10. The ID to find is in E2. Write an XLOOKUP formula that returns the product name, and explain why this formula would still work correctly if a new column were inserted between B and C.
Show answer
=XLOOKUP(E2, A2:A10, B2:B10). The return range is given as a reference to B2:B10, not as a column number. Inserting a column between B and C does not change which cells that reference points to, so the formula keeps returning names. A VLOOKUP with a hard-coded column number could return the wrong column after the same change.
Exercise
Your colleague uses Excel 2019 and opens a workbook that contains =XLOOKUP(E2, A2:A10, C2:C10). What will they most likely see, and what would you change in the file to avoid it?
Show answer
The function does not exist in Excel 2019, so the cell will most likely show #NAME? (the formula appears with an _xlfn. prefix). To avoid this, replace the formula with =INDEX(C2:C10, MATCH(E2, A2:A10, 0)) or =VLOOKUP(E2, A2:C10, 3, FALSE), both of which work in older versions.