Sub topic 5
XLOOKUP: a lookup range and a result range
Assume you know how to enter Google Sheets formulas, use cell and range references, write absolute references with $, and reference another sheet. This chapter focuses on how XLOOKUP separates the place it searches from the values it returns.
How XLOOKUP works
A lookup uses a key to find a row in a table. For example, a product ID can identify the row containing that product's name and price.
XLOOKUP has this structure:
=XLOOKUP(search_key, lookup_range, result_range, [missing_value], [match_mode], [search_mode])The first three arguments are the core:
search_keyis the value to find.lookup_rangeis the single row or column to search.result_rangeis the row or column containing the value to return.
Suppose column A contains product IDs and column C contains prices:
| A | B | C |
|---|---|---|
| P-101 | Notebook | 4.50 |
| P-102 | Desk lamp | 18.00 |
| P-103 | Cable | 7.25 |
To find the price for P-102, enter:
=XLOOKUP("P-102", A2:A100, C2:C100)The formula searches only A2:A100. When it finds P-102, it returns the value from the corresponding position in C2:C100.
You can use a cell as the key:
=XLOOKUP(E2, A2:A100, C2:C100)This makes the formula reusable. Change the value in E2, and the result updates.
Why separate ranges matter
With XLOOKUP, the lookup and result ranges are independent. They do not need to be part of one rectangular range, and the result range can be to the left of the lookup range.
For example, if product IDs are in column C and product names are in column A, use:
=XLOOKUP(E2, C2:C100, A2:A100, "Not found")The ranges should have matching lengths. If C2:C100 contains 99 cells, the result range should also contain 99 corresponding cells. The first cell in each range represents the same row, the second cell represents the same row, and so on.
Returning several columns
The result range can contain multiple adjacent columns. Google Sheets returns the matching row across those columns.
=XLOOKUP(E2, A2:A100, B2:D100)If the match is on row 12, the formula returns the values from B12:D12 into neighboring cells. This can return a product name, category, and price with one formula.
Make sure the cells to the right of the formula are empty. Otherwise, the result cannot expand into those cells.
Choosing a missing-value result
If no key matches, XLOOKUP returns #N/A by default. Add a fourth argument to show a readable result:
=XLOOKUP(E2, A2:A100, C2:C100, "Not found")You can also use IFNA when you need to wrap an existing lookup:
=IFNA(XLOOKUP(E2, A2:A100, C2:C100), "Not found")The missing_value argument is usually simpler when the only error you want to handle is a missing key.
A practical pattern
On a Orders sheet, suppose A2 contains a product ID. The product catalog is on a sheet named Products, with IDs in column A and prices in column C:
=XLOOKUP(A2, Products!A:A, Products!C:C, "Product missing")Use absolute or whole-column references when copying the formula down. The order ID can change by row, while the catalog ranges remain fixed.
Exercise
Product IDs are in Products!A2:A100, product names are in Products!B2:B100, and the ID to search is in E2. Write an XLOOKUP formula that returns the name and displays Unknown product when no match exists.
Show answer
=XLOOKUP(E2, Products!A2:A100, Products!B2:B100, "Unknown product")