Sub topic 1
What a lookup does and why XLOOKUP
Prerequisites
This chapter assumes you can do the following:
- Enter and copy formulas in Excel.
- Read cell references and ranges, including absolute references such as
$E$2. - Use Excel for Microsoft 365, Excel 2021 or later, or Excel for the web. Older versions do not have XLOOKUP.
What a lookup does
A lookup finds a value in one list and returns related information from the same position in another list. You give Excel a key, such as a product code or employee ID. Excel searches a column for that key and returns the matching item from a second column.
Typical uses include:
- Pulling a price from a product table using a product code.
- Finding a department name from an employee ID.
- Turning a numeric score into a letter grade.
Without a lookup, you would scan the table by eye or copy values by hand. Those values would go stale when the table changed. A lookup formula recalculates whenever the source data changes.
The two ranges must be the same size. The match in the lookup range at position 4 returns the item at position 4 of the return range.
Why XLOOKUP
Excel has had lookup functions for decades. The two best known are VLOOKUP and INDEX/MATCH. Both work, but each has weaknesses that XLOOKUP removes.
| Task | VLOOKUP | INDEX/MATCH | XLOOKUP |
|---|---|---|---|
| Look to the left of the key column | No | Yes | Yes |
| Exact match by default | No, you must add `FALSE` | No, you must add `0` | Yes |
| Return value is chosen by | Column number, which breaks if columns are inserted | A separate range | A separate range |
| Custom text when nothing matches | Needs `IFERROR` around it | Needs `IFERROR` around it | Built-in argument |
| Search from last to first | No | Not directly | Yes |
| Wildcards and next-smaller or next-larger match | Partly | Partly | Yes, with one argument |
The most common VLOOKUP failure is a column index number. If someone inserts a column in the table, the number points at the wrong column and the formula quietly returns wrong data. XLOOKUP takes the return range as a reference, so Excel adjusts it when the sheet changes.
A first XLOOKUP
Suppose A2:A10 holds product codes and C2:C10 holds prices. Cell E2 holds the code you want to look up. This formula returns its price:
=XLOOKUP(E2, A2:A10, C2:C10)Read it in three parts:
E2is the lookup value, the key to search for.A2:A10is the lookup array, the range that is searched.C2:C10is the return array, the range the answer comes from.
Excel finds the row in A2:A10 where the value equals E2. It then returns the value from the same row of C2:C10. If E2 contains a code that appears in A5, the result is whatever is in C5.
The lookup array and the return array do not need to be next to each other. The return array can sit to the left or the right of the lookup array, and on another sheet.
What comes next
The formula above uses only three of XLOOKUP's six arguments. The remaining three are optional. They control what happens when nothing matches, how Excel compares values, and which direction it searches. The next chapter introduces all six arguments.
Exercise
A table has employee IDs in B2:B50 and names in A2:A50. Cell D2 contains an ID. Write an XLOOKUP formula that returns the employee's name, and explain why VLOOKUP would need a workaround here.
Show answer
=XLOOKUP(D2, B2:B50, A2:A50). VLOOKUP can only return values from columns to the right of the lookup column. The names are in column A, to the left of the IDs in column B, so VLOOKUP would need helper columns or a rearranged table. XLOOKUP accepts the return array as a separate range, so position does not matter.