Find a course

Module 4: LookupsLesson 8 of 1213 min

XLOOKUP in Depth

Use XLOOKUP for exact matches, missing values, tiered rates with approximate match, multi-column results and latest-entry lookups.

Step 1 of 11Learn

Stop copying prices by hand

Jordan processes about 300 orders a week. Each order line has a product code, and the prices live in a separate price list of 900 products maintained by purchasing. Every Monday, Jordan finds each code in the price list and types the price into the order sheet. It takes two hours, and once a month a typo slips through.

A lookup formula does this in a second: find this code in the code column of the price list and bring back the price from the same row. That's the core idea behind every lookup function: a lookup value (the code), a lookup array to search (the codes in the price list), and a return array to take the answer from (the prices).

Excel has several lookup functions with different histories. VLOOKUP has been around since the 1980s and fills millions of workbooks. INDEX with MATCH became the power-user alternative. XLOOKUP, available in Microsoft 365 and Excel 2021 or later (and in Google Sheets), combines their strengths with safer defaults. This lesson covers XLOOKUP thoroughly; the next covers the older functions you'll still meet in shared files.

Step 2 of 11Learn

XLOOKUP basics

=XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])

Jordan's formula, with the price list as a table called Prices:

=XLOOKUP(A2, Prices[Code], Prices[Price])

Excel searches Prices[Code] for the code in A2 and returns the value in the same position of Prices[Price]. The lookup and return arrays must be the same height, but they can be anywhere: the return column can be to the left of the lookup column, on another sheet, or in another table.

Key behaviors:

  • Exact match is the default. If the code isn't there, XLOOKUP returns #N/A. It never quietly returns a "close" price, which is a major safety improvement over VLOOKUP.
  • Built-in not-found message. The fourth argument replaces #N/A with your own value: =XLOOKUP(A2, Prices[Code], Prices[Price], "Not listed"). No IFNA wrapper needed.
  • First match wins. If a code appears twice, XLOOKUP returns the first one, searching top to bottom.
  • Columns can move. Inserting a column inside the price list doesn't break anything, because you referenced the columns themselves, not a column number.
The three parts of every lookupLookup valueA2: "B-220"Search lookup arrayPrices[Code]Same spot in return arrayPrices[Price]Pricereturned

Step 3 of 11Practice · Choose one

=XLOOKUP("B-220", A2:A900, D2:D900) is entered, and "B-220" appears in A17 and again in A402. What does it return?

Step 4 of 11Learn

Approximate match for tiers and brackets

The fifth argument, match_mode, controls what counts as a match:

match_modeMeaning
0 (default)Exact match only
-1Exact match, or else the next smaller value
1Exact match, or else the next larger value
2Wildcard match using *, ? and ~

Mode −1 is how you look up tiered rates. Here is a commission table named Tiers:

Min salesRate
02%
10,0004%
25,0006%
50,0008%

For a rep with sales in B2:

=XLOOKUP(B2, Tiers[Min sales], Tiers[Rate], , -1)

Sales of $31,000 has no exact match, so XLOOKUP takes the next smaller threshold, 25,000, and returns 6%. Sales of exactly $25,000 matches exactly and also gets 6%. The empty argument between the commas skips if_not_found.

The same pattern works for tax brackets, shipping zones by weight, grade boundaries and volume discounts. Mode 1 suits the opposite question, such as "which box size is the smallest that fits 37 items?" Unlike VLOOKUP's approximate match, XLOOKUP's modes −1 and 1 don't require the table to be sorted, though sorted tables are easier for people to read.

Approximate match (mode -1): each sales figure falls back to the threshold at or below it2%$0+4%$10,000+6%$25,000+8%$50,000+0123456$31,000 → 6%Scale in $10,000s

Step 5 of 11Practice · Work it out

Using the Tiers table, what commission in dollars does a rep with $49,500 in sales earn? (Rate from =XLOOKUP(B2,Tiers[Min sales],Tiers[Rate],,-1) times sales.)

Step 6 of 11Learn

Returning several columns, searching from the bottom

Several columns at once. If the return array is several columns wide, XLOOKUP returns the whole row slice and spills it into neighboring cells. =XLOOKUP(A2, Staff[ID], Staff[[Name]:[Department]]) returns name, email and department for an employee ID in one formula, if those three columns sit side by side.

Latest entry. The sixth argument, search_mode, sets the search direction: 1 is first-to-last (default), −1 is last-to-first. In a price-change log where new rows are added at the bottom, =XLOOKUP(A2, Log[Code], Log[Price], , 0, -1) returns the most recent price for each code instead of the oldest. Modes 2 and −2 run a fast binary search on sorted data; you'll rarely need them.

Wildcards. With match_mode 2, =XLOOKUP("*"&E1&"*", Products[Name], Products[Code], , 2) finds the first product whose name contains the text in E1.

Two-way lookups. XLOOKUP can return a whole column, so you can nest one inside another. With months across row 1 and regions down column A: =XLOOKUP("West", A2:A6, XLOOKUP("Mar", B1:M1, B2:M6)). The inner XLOOKUP returns the March column; the outer one picks the West row from it.

search_mode -1 searches from the bottom: the newest C-17 price winsLog rowCodePrice2C-174.103A-029.994C-174.255B-112.406C-174.40Default search (top down) would return theoldest price, 4.10

Step 7 of 11Practice · Match the pairs

Match each XLOOKUP argument value to its effect.

Tap an answer, then tap the place where it belongs (or drag it there).

  1. if_not_found = "Missing"
  2. match_mode = -1
  3. match_mode = 2
  4. search_mode = -1
  5. match_mode omitted

Step 8 of 11Note

Step 9 of 11Practice · What would you do?

What would you do?

A log sheet records every price change, one row per change, newest at the bottom. Product C-17 appears five times. You need its current price. Which formula do you use?

Step 10 of 11Practice · Fill in the blanks

Fill in the blanks

For a tax bracket table sorted by the lowest income in each bracket, the XLOOKUP match_mode that returns the bracket for any income is .

Step 11 of 11Practice · Choose one

Why is XLOOKUP's default behavior safer than VLOOKUP's for a product price list?