1. Lighthouse

Level 6 · INDEX/MATCH, right to left

The request

From Shirley Chen, Buyer

“Lighting prices went up on March 1. Before I brief the team, I'd like the first February lighting lines next to today's list price, so we can see what changed. My catalog is on the right, sorted by name, with the id in the last column the way our old system exports it.”

Your goal

In E2:E21, use INDEX and MATCH to return each line's current list price: find the product_id from column B in the catalog's product_id column I2:I21 with an exact match (match type 0), and return the price on that row of H2:H21.

  • Fill E2:E21 with the right valuesnot done yet
  • With formulas, not typed numbersnot done yet
  • Use INDEX MATCHnot done yet

Your sheet

Excel
The sheet for this level
ABCDEFGHIJ
1order_item_idproduct_idquantityprice_paidlist_price nameunit_priceproduct_id
219100128254.99Ashford Linen Pendant Light349.00131
3191011271179.00Bramble Ceramic Floor Lamp31.99121
4191111351149.00Delancey Black Metal Wall Sconce54.99128
5191161392179.00Dune Black Metal Floor Lamp51.99133
619122133148.99Dune Black Metal Pendant Light189.00127
7191371322189.00Dune Ceramic Arc Lamp109.00129
8191461292109.00Fairhaven Brass Wall Sconce189.00132
919177122229.99Fern Rattan Desk Lamp379.00126
10191841352149.00Marlow Glass Wall Sconce349.00124
1119197122129.99Marlow Linen Floor Lamp219.00137
1219208128154.99Monroe Glass Desk Lamp29.99122
1319215122129.99Oakley Brass Table Lamp199.00138
1419221134192.99Pacifica Black Metal Arc Lamp279.00125
15192241311349.00Pacifica Black Metal Table Lamp409.00130
16192321271179.00Quarry Ceramic Picture Light329.00140
1719234122129.99Quarry Rattan Picture Light159.00136
18192371242349.00Ridge Ceramic Chandelier159.00135
1919239134392.99Rowan Ceramic Chandelier189.00139
20192471241349.00Sable Linen Table Lamp92.99134
21192491281254.99Sutton Brass Chandelier30.99123
22
23

Loading the editor…

    ResultPress Check to compare E2:E21

    Mote checks your result

    Press Check. Each right cell becomes a firefly in your lantern.

    The lesson

    Before XLOOKUP, the flexible lookup was a pair of functions: INDEX and MATCH. You will find it in almost every workbook you inherit, so it is worth knowing cold. Shirley’s catalog is the classic case for it: sorted by name in G1:I21, with the id in the last column. VLOOKUP can’t search it, because the ids aren’t in its first column.

    MATCH finds the position

    =MATCH(lookup_value, lookup_range, match_type)

    MATCH doesn’t return a value from the table. It returns where the value is: its position in the range. =MATCH(B2,$I$2:$I$21,0) looks for 128 in the catalog ids and returns 3, because 128 is the third id in I2:I21. The last argument, 0, means exact match.

    INDEX picks the value at a position

    =INDEX(range, position)

    =INDEX($H$2:$H$21,3) returns the third price in the catalog: 54.99. Put the two together and MATCH tells INDEX which row to read:

    =INDEX($H$2:$H$21,MATCH(B2,$I$2:$I$21,0))

    The search range and the return range are separate arguments, so the price column can sit left of the ids, as here, or anywhere else. The two ranges only need to start and end on the same rows.

    The missing 0

    MATCH has a trap in its default. Without the third argument it uses 1, an approximate match: it assumes the ids are sorted from small to large and jumps through them (a binary search) for the largest id that isn’t above yours. Row 4 is product 135, the Ridge Ceramic Chandelier, 159.00. MATCH(B4,$I$2:$I$21) returns 9 instead of 17, and INDEX hands back 349.00, another lamp’s price. No error. Fill that version down and only 3 of the 20 lines come out right, by luck. VLOOKUP without FALSE has exactly the same trap. Write the 0 every time you look up an id, a name or a code.

    VLOOKUP, INDEX/MATCH and XLOOKUP side by side

    VLOOKUP INDEX/MATCH XLOOKUP
    Direction key must be the first column, returns to the right any direction any direction
    Return column a number (4) a range a range
    A column inserted in the table the number now points at the wrong column still right still right
    Default match approximate: write FALSE approximate: write 0 exact
    Key not found #N/A, wrap in IFNA #N/A, wrap in IFNA if_not_found argument
    Where it works everywhere everywhere Excel 2021, Microsoft 365, Google Sheets

    The inserted-column row is the quiet one. In level 3, VLOOKUP(…,4,FALSE) returned the price because the price was the 4th column of F:I. Insert a “supplier” column inside the catalog and column 4 becomes the category, with no error. INDEX and MATCH point at the price column itself, so Excel adjusts their ranges when columns move. On this sheet, the XLOOKUP version is =XLOOKUP(B4,$I$2:$I$21,$H$2:$H$21), which also gives 159.00.

    Use XLOOKUP when everyone who opens the file has it; INDEX/MATCH when the file must work in older Excel; VLOOKUP with FALSE when the key is already the first column and you want the formula a colleague can read at a glance.

    Common mistakes

    • No 0 in MATCH. The lookup works on a sorted table and quietly fails on an unsorted one.
    • Unlocked ranges. The catalog has to stay put when you fill down: $H$2:$H$21, $I$2:$I$21.
    • Ranges that don’t line up. MATCH over I2:I21 with INDEX over H3:H22 returns the price from the row below every match.
    • INDEX and MATCH swapped. MATCH gets the id column, INDEX gets the column you want back.

    Pick what may run on this site. You can change this any time from "Cookie settings" at the bottom of every page.