Skip to content

Look up by row and column at once

Lookups in any direction8 minPremium

Builds on Look up in any direction with INDEX and MATCH and Look up a price with XLOOKUP.

A regional manager at a coffee roaster in Portland keeps last quarter's sales in a grid, with the blends down the side and the months across the top. On the weekly call, people ask for one number at a time, such as how many bags of one blend sold in February.

How it works

INDEX(grid, row_num, column_num) returns the value at a given row and column of a grid, both counted from its top-left cell. Two MATCHes supply the numbers: one finds the row among the labels down the side, the other finds the column among the labels across the top.

INDEX(grid, MATCH(row label, side labels, 0), MATCH(column label, top labels, 0))

Picture map coordinates. One MATCH gives the row, the other the column, and INDEX goes to the cell where they cross. Each MATCH has to line up with the grid: the side labels on the same rows as the grid, and the top labels over the same columns.

In Excel 2021 and later, XLOOKUP can do it in two steps. The inner XLOOKUP returns the whole row for one label, and the outer one picks the value under the other label from that row: XLOOKUP(column label, top labels, XLOOKUP(row label, side labels, grid)).

Example

A hotel in Lisbon has its nightly rates with the room types down A2:A5 and the seasons across B1:D1. The room is in B8 and the season in B9.

=INDEX(B2:D5,MATCH(B8,A2:A5,0),MATCH(B9,B1:D1,0))
Finds the row of the room type in B8 and the column of the season in B9, and returns the rate where they cross in B2:D5.

  1. Step 1: The first MATCH finds Double, from B8, 2nd in A2:A5, so the row is 2.
  2. Step 2: The second MATCH finds High, from B9, 3rd in B1:D1, so the column is 3.
  3. Step 3: INDEX takes row 2, column 3 of B2:D5, which is D3.
  4. Step 4: B10 shows that rate, €189.
One MATCH finds the row and the other the column. INDEX returns the rate where they cross. In B10, =INDEX(B2:D5,MATCH(B8,A2:A5,0),MATCH(B9,B1:D1,0)) returns €189.

Common mistakes

  • Swapping the two MATCHes puts MATCH(B9,B1:D1,0), the season's position, in the row's place and the room's in the column's, so you get another rate or #REF!. The row comes first.
  • MATCH(B9,A1:D1,0) counts the corner cell A1 among the seasons, so every season lands one column to the right of where it should.
  • A MATCH without its 0 makes an approximate match, which on unsorted labels can pick the wrong row or column.

In short

  • INDEX takes a row number and then a column number, and one MATCH finds each.
  • Line each MATCH up with the grid: side labels on its rows, top labels over its columns.
  • In Excel 2021 and later, XLOOKUP(column label, top labels, XLOOKUP(row label, side labels, grid)) does the same.

Practice

Premium

4 exercises: 3 formulas and 1 selection.

Practice is part of Premium

Every lesson is free to read, and you can practice the free lessons without an account. This lesson's exercises are part of Premium, which you add to a free account.