SheetSense

Two-way lookup with INDEX, MATCH, MATCH

INDEX with two MATCH functions returns the value where a matching row and a matching column meet in a grid, such as a budget by cost center and month.

fx
=INDEX($B$2:$M$50,MATCH(H2,$A$2:$A$50,0),MATCH(H3,$B$1:$M$1,0))

The sheet: Budget sheet: A2:A50 lists cost centers, B1:M1 holds month headers Jan to Dec, and B2:M50 holds budget amounts. H2 has a cost center and H3 has a month.

How it works, step by step

  1. 01H2 holds the cost center, for example Marketing, and H3 holds the month, for example Mar.
  2. 02MATCH(H2,$A$2:$A$50,0) finds Marketing in the cost center column and returns its row position, say 4.
  3. 03MATCH(H3,$B$1:$M$1,0) finds Mar in the header row and returns its column position, 3.
  4. 04INDEX($B$2:$M$50,4,3) returns the amount at row 4, column 3 of the grid, which is the Marketing budget for March.

The same logic in four tools

Excel
=INDEX($B$2:$M$50,MATCH(H2,$A$2:$A$50,0),MATCH(H3,$B$1:$M$1,0))
Google Sheets
=INDEX($B$2:$M$50,MATCH(H2,$A$2:$A$50,0),MATCH(H3,$B$1:$M$1,0))
SQL
-- budget stored in long format: one row per cost center and month
SELECT amount
FROM budget
WHERE cost_center = 'Marketing'
  AND month = 'Mar';
Python (pandas)
import pandas as pd

# budget has a cost_center column plus one column per month, like the sheet
grid = budget.set_index("cost_center")
value = grid.loc["Marketing", "Mar"]

Mistakes that break it

  • !The row MATCH must cover the same rows as the INDEX grid ($A$2:$A$50 with $B$2:$M$50), and the column MATCH must cover the same columns ($B$1:$M$1). An offset of one returns the neighboring cell.
  • !Month headers entered as real dates (1-Mar-2026 formatted to show Mar) will not match the text Mar in H3. Make both sides text or both dates.
  • !In Excel 365, Excel 2021, and Google Sheets, =XLOOKUP(H2,$A$2:$A$50,XLOOKUP(H3,$B$1:$M$1,$B$2:$M$50)) does the same thing. The inner XLOOKUP returns the Mar column, and the outer one picks the Marketing row from it.
  • !SQL tables usually store this data in long format, one row per cost center and month, so the lookup becomes a WHERE on two columns. A wide table with one column per month needs the month hard-coded or unpivoted first.

Common questions

How do I look up a value by row and column in Excel?
Use INDEX with two MATCH functions. One MATCH finds the row number, the other finds the column number, and INDEX returns the cell where they meet.
Can XLOOKUP do a two-way lookup?
Yes, by nesting one XLOOKUP inside another. The inner one matches the column header and returns that whole column, and the outer one matches the row label within it.
Why does INDEX MATCH MATCH return #REF!?
One of the MATCH results is larger than the INDEX grid, usually because the header range is wider than the grid or the row range is longer. Make $A$2:$A$50 match the grid's rows and $B$1:$M$1 match its columns.

Got a version of this with your own ranges?

Paste it into the free translator and get the same breakdown for your exact formula. To run it against a real file, upload the CSV and describe the formula you need in a sentence.