Looking up values: XLOOKUP and VLOOKUP
Pull information from another table automatically: find prices and categories with XLOOKUP, understand the older VLOOKUP you will meet at work, handle missing items, and look up bands such as commission rates.
🎯 By the end of this lesson you will be able to:
- Look up a value in another table with XLOOKUP
- Read and write VLOOKUP formulas, and know their limits
- Handle missing matches and look up ranges such as rate bands
Outline
What you'll learn and why it matters
Information usually lives in more than one table: orders in one, product prices in another, staff details in a third. Lookups bring them together: for each order, find its product in the price list and fetch the price. It is the skill most often tested in Excel job interviews.
XLOOKUP
=XLOOKUP(lookup_value, lookup_array, return_array): find lookup_value in lookup_array, and return the matching item from return_array.
Worksheet: Sales
| Row | A | B | C | D | E | F | G |
|---|---|---|---|---|---|---|---|
| 1 | Product | Units | Price | Product | Category | Price | |
| 2 | Sketchbook | 11 | 300 | Notebook | Paper | 120 | |
| 3 | Pen set | 4 | 250 | Pen set | Writing | 250 | |
| 4 | Sketchbook | 3 | 300 | Backpack | Bags | 1500 | |
| 5 | Notebook | 9 | 120 | Water bottle | Accessories | 400 | |
| 6 | Notebook | 2 | 120 | Desk lamp | Accessories | 1200 | |
| 7 | Pen set | 8 | 250 | Sketchbook | Paper | 300 |
Formulas (green cells)
- C2 =XLOOKUP(A2,$E$2:$E$7,$G$2:$G$7) → 300
- C3 =XLOOKUP(A3,$E$2:$E$7,$G$2:$G$7) → 250
- C4 =XLOOKUP(A4,$E$2:$E$7,$G$2:$G$7) → 300
- C5 =XLOOKUP(A5,$E$2:$E$7,$G$2:$G$7) → 120
- C6 =XLOOKUP(A6,$E$2:$E$7,$G$2:$G$7) → 120
- C7 =XLOOKUP(A7,$E$2:$E$7,$G$2:$G$7) → 250
| Part | Here | Meaning |
|---|---|---|
| lookup_value | A2 | What to look for: this order's product |
| lookup_array | $E$2:$E$7 | Where to look: the product names |
| return_array | $G$2:$G$7 | What to bring back: the prices |
To fetch the category instead, just change the return array to $F$2:$F$7. In a real workbook the Products table is usually on its own sheet: then the range looks like Products!$A$2:$A$7.
When there is no match
If the value is not in the table, XLOOKUP returns #N/A. Give a fourth argument to show something friendlier:
Worksheet: Lookup
| Row | A | B | C | D | E |
|---|---|---|---|---|---|
| 1 | Product | Price | Product | Price | |
| 2 | Backpack | 1500 | Notebook | 120 | |
| 3 | Stapler | Not found | Backpack | 1500 | |
| 4 | Stapler | #N/A | Desk lamp | 1200 |
Formulas (green cells)
- B2 =XLOOKUP(A2,$D$2:$D$4,$E$2:$E$4,"Not found") → 1500
- B3 =XLOOKUP(A3,$D$2:$D$4,$E$2:$E$4,"Not found") → Not found
- B4 =XLOOKUP(A4,$D$2:$D$4,$E$2:$E$4) → #N/A
VLOOKUP: the one you will meet at work
Millions of existing spreadsheets use the older =VLOOKUP(lookup_value, table, column_number, FALSE). It looks in the first column of the table and returns the value from the column number you give:
Worksheet: Sales
| Row | A | B | C | D | E | F | G |
|---|---|---|---|---|---|---|---|
| 1 | Product | Units | Price (VLOOKUP) | Product | Category | Price | |
| 2 | Sketchbook | 11 | 300 | Notebook | Paper | 120 | |
| 3 | Pen set | 4 | 250 | Pen set | Writing | 250 | |
| 4 | Sketchbook | 3 | 300 | Backpack | Bags | 1500 | |
| 5 | Notebook | 9 | 120 | Water bottle | Accessories | 400 | |
| 6 | Notebook | 2 | 120 | Desk lamp | Accessories | 1200 | |
| 7 | Pen set | 8 | 250 | Sketchbook | Paper | 300 |
Formulas (green cells)
- C2 =VLOOKUP(A2,$E$2:$G$7,3,FALSE) → 300
- C3 =VLOOKUP(A3,$E$2:$G$7,3,FALSE) → 250
- C4 =VLOOKUP(A4,$E$2:$G$7,3,FALSE) → 300
- C5 =VLOOKUP(A5,$E$2:$G$7,3,FALSE) → 120
- C6 =VLOOKUP(A6,$E$2:$G$7,3,FALSE) → 120
- C7 =VLOOKUP(A7,$E$2:$G$7,3,FALSE) → 250
| XLOOKUP | VLOOKUP | |
|---|---|---|
| Look in | Any column | Only the first column of the table |
| Return | Any column, left or right | A column number, to the right only |
| Exact match | By default | Only if you write FALSE as the 4th argument |
| Inserting a column in the table | Keeps working | Can silently return the wrong column |
| Works in Excel 2016 and older | No | Yes |
Looking up bands: approximate match
For bands, such as *commission depends on the sales level*, list the lower edge of each band in ascending order. XLOOKUP with a 5th argument of -1 finds the exact value or the next smaller one:
Worksheet: Commission
| Row | A | B | C | D | E | F |
|---|---|---|---|---|---|---|
| 1 | Salesperson | Sales | Rate | From | Rate | |
| 2 | Asha | 14250 | 4% | 0 | 2% | |
| 3 | Ravi | 9870 | 2% | 10000 | 4% | |
| 4 | Meera | 21430 | 6% | 20000 | 6% |
Formulas (green cells)
- C2 =XLOOKUP(B2,$E$2:$E$4,$F$2:$F$4,,-1) → 4%
- C3 =XLOOKUP(B3,$E$2:$E$4,$F$2:$F$4,,-1) → 2%
- C4 =XLOOKUP(B4,$E$2:$E$4,$F$2:$F$4,,-1) → 6%
Practice
Guided exercise
Fetch the category
For each order, look up the product's category from the Products table.
- In C2 type
=XLOOKUP(A2,$E$2:$E$7,$F$2:$F$7). - Copy it down to C7.
Show the solution
Worksheet: Sales
| Row | A | B | C | D | E | F | G |
|---|---|---|---|---|---|---|---|
| 1 | Product | Units | Category | Product | Category | Price | |
| 2 | Sketchbook | 11 | Paper | Notebook | Paper | 120 | |
| 3 | Pen set | 4 | Writing | Pen set | Writing | 250 | |
| 4 | Sketchbook | 3 | Paper | Backpack | Bags | 1500 | |
| 5 | Notebook | 9 | Paper | Water bottle | Accessories | 400 | |
| 6 | Notebook | 2 | Paper | Desk lamp | Accessories | 1200 | |
| 7 | Pen set | 8 | Writing | Sketchbook | Paper | 300 |
Formulas (green cells)
- C2 =XLOOKUP(A2,$E$2:$E$7,$F$2:$F$7) → Paper
- C3 =XLOOKUP(A3,$E$2:$E$7,$F$2:$F$7) → Writing
- C4 =XLOOKUP(A4,$E$2:$E$7,$F$2:$F$7) → Paper
- C5 =XLOOKUP(A5,$E$2:$E$7,$F$2:$F$7) → Paper
- C6 =XLOOKUP(A6,$E$2:$E$7,$F$2:$F$7) → Paper
- C7 =XLOOKUP(A7,$E$2:$E$7,$F$2:$F$7) → Writing
How to get there: Only the return array changes, from the Price column (G) to the Category column (F). The $ signs keep the table in place as the formula is copied down.
Your turn
Line totals with a lookup
Work out each order's total in one formula: units times the price looked up from the table.
Show the solution
Worksheet: Sales
| Row | A | B | C | D | E | F | G |
|---|---|---|---|---|---|---|---|
| 1 | Product | Units | Total | Product | Category | Price | |
| 2 | Sketchbook | 11 | 3300 | Notebook | Paper | 120 | |
| 3 | Pen set | 4 | 1000 | Pen set | Writing | 250 | |
| 4 | Sketchbook | 3 | 900 | Backpack | Bags | 1500 | |
| 5 | Notebook | 9 | 1080 | Water bottle | Accessories | 400 | |
| 6 | Notebook | 2 | 240 | Desk lamp | Accessories | 1200 | |
| 7 | Pen set | 8 | 2000 | Sketchbook | Paper | 300 |
Formulas (green cells)
- C2 =B2*XLOOKUP(A2,$E$2:$E$7,$G$2:$G$7) → 3300
- C3 =B3*XLOOKUP(A3,$E$2:$E$7,$G$2:$G$7) → 1000
- C4 =B4*XLOOKUP(A4,$E$2:$E$7,$G$2:$G$7) → 900
- C5 =B5*XLOOKUP(A5,$E$2:$E$7,$G$2:$G$7) → 1080
- C6 =B6*XLOOKUP(A6,$E$2:$E$7,$G$2:$G$7) → 240
- C7 =B7*XLOOKUP(A7,$E$2:$E$7,$G$2:$G$7) → 2000
How to get there: A lookup can sit inside a bigger formula: XLOOKUP returns the price, which is multiplied by the units. 11 sketchbooks at 300 make 3,300.
Common mistakes
Not locking the lookup table with $
You see: #N/A further down the column as the range slides
Fix: Use $E$2:$E$7, or press F4 on the range.
VLOOKUP without FALSE
You see: Wrong values with no error
Fix: Always end VLOOKUP with , FALSE (or use XLOOKUP).
Extra spaces or different spelling
You see: #N/A for an item you can see
Fix: Clean the data with TRIM and check spelling.
Lookup and return arrays of different sizes
You see: #VALUE!
Fix: Both arrays must cover the same rows.
Recap
- =XLOOKUP(value, lookup_array, return_array) finds a value and returns the matching item.
- Add a 4th argument for a friendly result when nothing matches; lock table ranges with $.
- VLOOKUP(value, table, column, FALSE) is older: first column only, and always use FALSE.
- For bands, list lower edges in ascending order and use XLOOKUP's match mode -1.
Key terms
- Lookup
- Finding a value in one table and returning related information from it.
- Exact match
- A lookup that only succeeds when the value is found exactly.
- #N/A
- The error a lookup returns when no match is found.
Check your understanding
Answer all 4 questions, then check your answers to see an explanation for each one.
1. In =XLOOKUP(A2,E2:E7,G2:G7), what is G2:G7?
2. Why end VLOOKUP with FALSE?
3. A lookup returns #N/A for 'Backpack', which you can see in the table. What is the most likely cause?
4. What can XLOOKUP do that VLOOKUP cannot?
Mark this lesson complete
Finished this lesson?
When you have worked through the examples and exercises, mark it complete to save your progress.