Lookups: VLOOKUP, HLOOKUP, XLOOKUP
Lesson opener
In one line: Join customer attributes onto sales rows - same idea as SQL JOIN.
Why it matters: This shows up at work when you need to join customer attributes onto sales rows - same idea as SQL JOIN..
Before this lesson: Advanced functions
If you have been through xl1-xl4, you already know more Excel than most people in most offices.
Before you start
| Resource | Link |
|---|---|
| Previous | Advanced functions |
| Next | Pivot tables |
What you will learn
Join customer attributes onto sales rows — same idea as SQL JOIN.

Setup — Two tables
See this layout on your screen — two separate tables, one key column in common.
Customers (master / dimension table):
| CustomerID | Segment | Region |
|---|---|---|
| C001 | Gold | North |
| C002 | Silver | South |
| C003 | Bronze | East |
Sales (fact table — many rows per customer):
| OrderID | CustomerID | Revenue | Month |
|---|---|---|---|
| O101 | C001 | 500 | Jan |
| O102 | C002 | 300 | Jan |
| O103 | C001 | 200 | Feb |
Customers: key =CustomerIDSales: key =CustomerID, facts =Revenue,Month
Goal: add Segment to each sales row so you can slice revenue by tier in a pivot.
Press Ctrl+T on each block. Name them Customers and Sales. That is your join setup — same pattern as every workplace report.
Why XLOOKUP is better than VLOOKUP
VLOOKUP has three annoying limitations:
- The column you search must always be on the left. If your key column moves right, VLOOKUP stops working.
- If you insert a column, the formula breaks. VLOOKUP counts column position (2, 3, 4…) — not column names. Add a column and every formula points at the wrong data.
- It cannot look to the left of the search column. Need a value sitting left of the ID? VLOOKUP cannot reach it.
XLOOKUP removes all three problems. You name the lookup column and return column separately. Insert columns freely. Look left or right.
If you are learning now, learn XLOOKUP. Only use VLOOKUP if you are maintaining someone else's old file.
XLOOKUP (preferred)
Pull segment onto each sale
1. THE PROBLEM
Sales rows only have CustomerID — without a join you cannot slice revenue by segment, and copying segment down by hand breaks when the master changes.
2. PLAIN ENGLISH VERSION
Search the customer table for this row's ID. Bring back the segment sitting on the matching row.
3. WHEN TO USE IT
Every order row needs a column from the customer table matched on CustomerID for pivot and chart work downstream.
4. THE FORMULA
=XLOOKUP([@CustomerID],Customers[CustomerID],Customers[Segment],"Not found")5. BREAKDOWN
[@CustomerID]→ the ID on this sales row (structured table syntax for the current row)Customers[CustomerID]→ the column to search in the customer tableCustomers[Segment]→ what to return when the ID matches"Not found"→ friendly text instead of#N/Awhen there is no matchXLOOKUP( )→ the modern lookup — exact match by default
6. WHAT YOU WILL SEE
Gold, Silver, Bronze, or Not found on each sales row.
Try it yourself
Type the Setup tables above on one sheet. Click the first empty cell in Sales next to the data — header Segment. Type:
=XLOOKUP([@CustomerID],Customers[CustomerID],Customers[Segment],"Not found")Press Enter. Copy down. O101 and O103 show Gold. O102 shows Silver.
IFNA around XLOOKUP
1. THE PROBLEM
#N/A in a column of 10,000 rows makes stakeholders nervous — even when missing keys are expected.
2. PLAIN ENGLISH VERSION
Run the same lookup, but swap only the missing-match error for a clean label.
3. WHEN TO USE IT
Weekly sales refresh where new CustomerIDs appear before master data catches up.
4. THE FORMULA
=IFNA(XLOOKUP([@CustomerID],Customers[CustomerID],Customers[Segment]),"Unknown")5. BREAKDOWN
XLOOKUP(...)→ same lookup as aboveIFNA( )→ catches only#N/Aerrors (not division or other failures)"Unknown"→ what to show when the ID is not in the customer table
6. WHAT YOU WILL SEE
A segment name or Unknown — never a raw #N/A in the column.
Try it yourself
Add row O104 with CustomerID C999 (not in Customers). Use the IFNA formula. You see Unknown instead of #N/A.
MATCH and XMATCH — row position
1. THE PROBLEM
Sometimes you need where a value sits in a list before pulling a value with INDEX — or to check if an ID exists at all.
2. PLAIN ENGLISH VERSION
Tell me the row number where this CustomerID appears in the master list.
3. WHEN TO USE IT
Pairing with INDEX for a flexible lookup, or auditing whether an ID exists in the master.
4. THE FORMULA
=MATCH([@CustomerID],Customers[CustomerID],0)
=XMATCH([@CustomerID],Customers[CustomerID],0,1)5. BREAKDOWN
MATCH(lookup, range, 0)→ classic position finder;0means exact matchXMATCH(lookup, range, 0, 1)→ newer version with extra search modes;0= exact,1= search first to last[@CustomerID]→ the key on this rowCustomers[CustomerID]→ the column to search
6. WHAT YOU WILL SEE
A number like 1, 2, or 3 — the row position. #N/A if the ID is missing.
Try it yourself
For CustomerID C002 in Sales row O102:
=MATCH([@CustomerID],Customers[CustomerID],0)You see 2 (C002 is the second row in Customers).
VLOOKUP (legacy)
1. THE PROBLEM
Plenty of workplaces still run sheets built years ago on VLOOKUP — you need to read and fix them even when XLOOKUP is available.
2. PLAIN ENGLISH VERSION
Search down the first column of a table range. Return a value from a column you count by position (2nd, 3rd…).
3. WHEN TO USE IT
Maintaining a legacy commission workbook someone else built before XLOOKUP shipped.
4. THE FORMULA
=VLOOKUP([@CustomerID],Customers,2,FALSE)(Assumes CustomerID is column 1 and Segment is column 2 in the Customers table range.)
5. BREAKDOWN
[@CustomerID]→ the customer ID to findCustomers→ the whole lookup table (ID must be in the leftmost column)2→ return value from the 2nd column of that range (Segment if ID is column 1)FALSE→ exact match only (never use TRUE for IDs)VLOOKUP( )→ legacy vertical lookup
6. WHAT YOU WILL SEE
Gold, Silver, or Bronze — same segment as XLOOKUP when the table layout matches.
Try it yourself
Use the same Setup tables. In Sales Segment column:
=VLOOKUP([@CustomerID],Customers,2,FALSE)O101 → Gold. O102 → Silver. Same results as XLOOKUP — until someone inserts a column left of Segment and VLOOKUP breaks.
VLOOKUP approximate match (TRUE) — tax brackets only
When TRUE is correct: Sorted lookup tables where you want the largest value less than or equal to your input — commission tiers, tax brackets, shipping weight bands.
Never use TRUE for customer IDs, order IDs, or product codes. You will get wrong matches silently.
=VLOOKUP([@Revenue],CommissionTable,2,TRUE)| Revenue input | Table has 0, 5000, 10000 | Returns tier for |
|---|---|---|
| 7500 | Sorted ascending | 5000 tier |
| 12000 | Sorted ascending | 10000 tier |
Rule: The lookup column must be sorted ascending or approximate match returns garbage. For IDs, always use FALSE (exact) or switch to XLOOKUP with 0 as match mode.
HLOOKUP (rare)
1. THE PROBLEM
Your labels run across a row instead of down a column — VLOOKUP and XLOOKUP search vertically and miss them.
2. PLAIN ENGLISH VERSION
Search left to right along the top row of a range. Return a value from a row you count by position.
3. WHEN TO USE IT
Small matrix exports where month names sit in row 1 and metrics sit in rows below — uncommon for flat customer/sales tables.
4. THE FORMULA
=HLOOKUP("Q1",QuarterMatrix,2,FALSE)5. BREAKDOWN
"Q1"→ the value to find in the first row of the rangeQuarterMatrix→ the whole block (header row plus the data rows). A header-only name such asQuarterHeadershas no row 2, sorow_index2 returns#REF!2→row_indexis relative to the range you pass, not to the sheet: 1 = the header row insideQuarterMatrix, 2 = the first data row (Revenue)FALSE→ exact matchHLOOKUP( )→ horizontal lookup — mirror image of VLOOKUP
6. WHAT YOU WILL SEE
The metric value under the Q1 column — one number from the matrix.
Try it yourself
| Q1 | Q2 | Q3 | |
|---|---|---|---|
| Revenue | 10000 | 12000 | 11000 |
| Orders | 50 | 55 | 48 |
Select the block including headers, name it QuarterMatrix. Type under the table:
=HLOOKUP("Q1",QuarterMatrix,2,FALSE)You see 10000 (Revenue row under Q1).
Compare to SQL
| Excel | SQL |
|---|---|
| XLOOKUP | JOIN |
| #N/A | no matching row |
| Joins module | same logic |
Plain English: XLOOKUP on Sales.CustomerID → Customers.CustomerID is the same question as SELECT sales.*, customers.segment FROM sales JOIN customers ON sales.customer_id = customers.customer_id. Excel does it per row with a formula. SQL does it once for the whole table.
Common errors
| Error | Cause | Fix |
|---|---|---|
| #N/A | Key not in lookup table | Check spelling, TRIM spaces, or wrap with IFNA |
| #REF! | Deleted columns | Rebuild formula range; prefer structured table refs |
| Wrong segment | Approximate match (TRUE) | Use FALSE / exact match for IDs |
| #VALUE! | Text ID vs number ID | Make both columns the same type |
#N/A means Excel looked and found nothing — like a SQL JOIN with no matching row. #REF! means a column your formula pointed at was deleted. Wrong segment with VLOOKUP often means someone used TRUE (approximate) instead of FALSE — never do that for customer IDs.
Essential commands
| Command / action | What it does |
|---|---|
=XLOOKUP(lookup, lookup_array, return_array, [if_not_found]) | Modern lookup (exact match). |
=VLOOKUP(lookup, table, col_index, FALSE) | Legacy vertical lookup; FALSE = exact. |
=HLOOKUP(lookup, table, row_index, FALSE) | Horizontal lookup across a header row. |
=IFNA(XLOOKUP(...), "fallback") | Friendly message when key missing. |
=INDEX(col, MATCH(key, key_col, 0)) | Classic flexible lookup (pre-XLOOKUP). |
Practice — no download needed
Open a blank Excel sheet. Follow these steps exactly:
Step 1: Type these two tables (press Ctrl+T on each, name them Customers and Sales):
Customers (starting A1):
| CustomerID | Segment | Region |
|---|---|---|
| C001 | Gold | North |
| C002 | Silver | South |
| C003 | Bronze | East |
Sales (starting F1):
| OrderID | CustomerID | Revenue | Month |
|---|---|---|---|
| O101 | C001 | 500 | Jan |
| O102 | C002 | 300 | Jan |
| O103 | C001 | 200 | Feb |
| O104 | C003 | 150 | Feb |
Step 2: Click J2 (first data row under header Segment in Sales). Type:
=XLOOKUP([@CustomerID],Customers[CustomerID],Customers[Segment],"Not found")Press Enter. Copy down through J5.
Step 3: What do you see?
J2 → Gold. J3 → Silver. J4 → Gold. J5 → Bronze.
If you see #NAME?: make sure both ranges are Excel Tables named Customers and Sales.
If you see #N/A: check CustomerID spelling matches exactly (C001 not C01).
Step 4: Pick two rows at random — say O101 and O104. Trace by hand: O101 has C001 → Customers row 1 → Gold. O104 has C003 → row 3 → Bronze. Your formula results should match.
Challenge (optional): Add O105 with CustomerID C999. Change the formula to use IFNA with Unknown. Add C004 to Customers, refresh — does O105 update if you fix the ID to C004?
Checklist
- [ ] Can you explain why XLOOKUP beats VLOOKUP on column inserts and left lookups?
- [ ] Can you pull Segment onto every Sales row using XLOOKUP and CustomerID?
- [ ] Can you replace #N/A with Unknown using IFNA for missing keys?
- [ ] Can you read a legacy VLOOKUP formula and say which column it returns?
- [ ] Can you explain how XLOOKUP on two tables is like a SQL JOIN?
- [ ] Can you build both tables and run the join without downloading a file?