Rana Maninder Singh
Lesson 5 of 8Excel & Spreadsheets

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

ResourceLink
PreviousAdvanced functions
NextPivot tables


What you will learn

Join customer attributes onto sales rows — same idea as SQL JOIN.

SQL joins explained
SQL joins explained

Setup — Two tables

See this layout on your screen — two separate tables, one key column in common.

Customers (master / dimension table):

CustomerIDSegmentRegion
C001GoldNorth
C002SilverSouth
C003BronzeEast

Sales (fact table — many rows per customer):

OrderIDCustomerIDRevenueMonth
O101C001500Jan
O102C002300Jan
O103C001200Feb

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:

  1. The column you search must always be on the left. If your key column moves right, VLOOKUP stops working.
  2. 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.
  3. 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

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

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

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

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 inputTable has 0, 5000, 10000Returns tier for
7500Sorted ascending5000 tier
12000Sorted ascending10000 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

6. WHAT YOU WILL SEE

The metric value under the Q1 column — one number from the matrix.

Try it yourself

Q1Q2Q3
Revenue100001200011000
Orders505548

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

ExcelSQL
XLOOKUPJOIN
#N/Ano matching row
Joins modulesame 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

ErrorCauseFix
#N/AKey not in lookup tableCheck spelling, TRIM spaces, or wrap with IFNA
#REF!Deleted columnsRebuild formula range; prefer structured table refs
Wrong segmentApproximate match (TRUE)Use FALSE / exact match for IDs
#VALUE!Text ID vs number IDMake 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 / actionWhat 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):

CustomerIDSegmentRegion
C001GoldNorth
C002SilverSouth
C003BronzeEast

Sales (starting F1):

OrderIDCustomerIDRevenueMonth
O101C001500Jan
O102C002300Jan
O103C001200Feb
O104C003150Feb

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?