Sub topic 13
Looking Up by Row and Column Together
A two-way lookup returns one value from a grid by using a row label and a column header together. Financial models use this pattern for rate cards, FX tables, price lists, and scenario grids. This chapter shows two builds, one with INDEX and MATCH and one with nested XLOOKUP, and covers the errors that tend to appear.
Prerequisites
This chapter assumes you can already do the following:
- Write an exact-match
MATCHand useINDEXwith a single position. - Use
XLOOKUPwith a lookup array and a return array. - Anchor references with
$so a formula can be copied across and down. - Read a flat table where each row label is unique.
What a two-way lookup solves
A one-way lookup uses one key, such as a row label, to find a value in a single column. A two-way lookup needs two keys because the answer sits where a row and a column cross.
Suppose a rate table lists cost centers down the side and fiscal years across the top. The question "what is the rate for Sales in FY26?" has two parts. The row key is Sales and the column key is FY26. Neither key alone identifies the cell.
| Cost center | FY24 | FY25 | FY26 |
|---|---|---|---|
| Sales | 3.0% | 3.2% | 3.5% |
| Operations | 2.5% | 2.6% | 2.8% |
| Support | 2.0% | 2.1% | 2.3% |
The grid above is a layout for lookup, not a flat ledger. Row labels in the first column must be unique. Headers in the top row must be unique. If either list repeats a value, the lookup returns the first match and ignores the rest.
Build 1: INDEX with two MATCH functions
INDEX accepts a row number and a column number. Each MATCH supplies one of them.
=INDEX(Rates!$C$3:$H$12, MATCH($A5, Rates!$B$3:$B$12, 0), MATCH(C$4, Rates!$C$2:$H$2, 0))Read the formula in three parts:
- The first argument,
Rates!$C$3:$H$12, is the body of the grid. It holds values only. It excludes the row labels and the header row. - The first
MATCHfinds the position of the row label in$A5withinRates!$B$3:$B$12. The0forces an exact match. - The second
MATCHfinds the position of the header inC$4withinRates!$C$2:$H$2.
INDEX then returns the cell at that row and column position inside the body.
Why the ranges must line up
MATCH returns a position, not a sheet address. The position is counted from the first cell of the range you give it. That is why the label range starts at row 3 and the body also starts at row 3. The header range starts at column C and the body also starts at column C. If the body began one row higher than the label range, every result would be shifted by one row, and no error would appear.
Check the alignment whenever you build the formula:
- The label range and the body must have the same number of rows and start on the same row.
- The header range and the body must have the same number of columns and start on the same column.
Why the anchors are mixed
The formula uses $A5 and C$4. The $ in $A5 locks column A, so copying the formula to the right keeps reading the row label from column A while the row number still changes as you copy down. The $ in C$4 locks row 4, so copying down keeps reading the header row while the column letter still changes as you copy right. One formula then fills the whole output block.
Build 2: nested XLOOKUP
XLOOKUP can do the same job without any position numbers. The inner XLOOKUP returns a whole column. The outer XLOOKUP then picks one row from that column.
=XLOOKUP($A5, Rates!$B$3:$B$12, XLOOKUP(C$4, Rates!$C$2:$H$2, Rates!$C$3:$H$12))Work from the inside out:
- The inner
XLOOKUPlooks for the header inC$4acrossRates!$C$2:$H$2. The return array is the full body,Rates!$C$3:$H$12. Because the lookup array runs across columns,XLOOKUPreturns the entire matching column of the body. - The outer
XLOOKUPlooks for the row label in$A5withinRates!$B$3:$B$12. Its return array is the column the inner formula produced. The returned value is the one in the matching row.
The inner result is an array, not a single number. The outer function treats it as its return array, which works because it has the same number of rows as the label range.
Defaults to know
XLOOKUP defaults to an exact match, so you do not need a 0. If a key is missing, each XLOOKUP returns #N/A unless you supply the fourth argument. For a missing row label or header, a text message inside the nested formula can hide the problem, because the outer function may then receive text where it expects an array. Handle not-found cases on the outermost function, or by checking the keys separately, as described below.
Comparing the two builds
| Point | INDEX with two MATCH | Nested XLOOKUP |
|---|---|---|
| Excel version | Works in all versions | Needs a version that includes XLOOKUP |
| Reading the formula | Position numbers are explicit | Shorter, but the inner array is less obvious |
| Exact match | Must type `0` | Default |
| Auditing | Each MATCH can be tested in its own cell | The inner XLOOKUP can be evaluated with Evaluate Formula |
| Range alignment | You must keep the body aligned with both key ranges | Sizes must match, or Excel returns an error |
Both builds return the same value on the same grid. Choose by compatibility and by what your reviewers can read quickly. Many teams pick INDEX with MATCH when the workbook is shared with people on older Excel, and XLOOKUP otherwise.
Common errors
Header types that look equal but are not
A header typed as the number 2026 will not match a header typed as the text "2026". Both look the same on screen. If the headers come from a date or year row, make sure the lookup cell and the header row hold the same type. A quick test is =ISNUMBER(C$4) against =ISNUMBER(Rates!C2).
Trailing spaces and inconsistent labels
"Sales " with a trailing space does not match "Sales". Clean the labels at the source rather than patching each lookup. TRIM on the label is a stopgap, not a fix.
Duplicate keys
If two rows share the label "Sales", both builds return the value for the first one. The second row is never reached. Count the key to detect this:
=COUNTIF(Rates!$B$3:$B$12, $A5)A result of 1 means the key is present once. A result of 0 means missing. A result above 1 means duplicated. Apply the same check to the header row with the header cell.
Range misalignment
If the body range is one row shorter than the label range, INDEX can still return a value for most rows, but the last label points to a row that is not in the body, and you get #REF!. Worse, if the body starts one row too high or too low, the values are silently wrong. Always test one known corner of the grid by hand: look up the top-left and bottom-right entries and compare them to the cells you see.
Wrapping everything in IFERROR
IFERROR around a lookup turns every error into a blank or a zero. That hides a missing key and makes a total look reasonable when it is wrong. Prefer a visible flag, such as a separate check cell, and let the lookup show #N/A while you build the model.
Making the keys safe
Two small checks around the lookup keep the grid auditable. Put them next to the output block.
=COUNTIF(Rates!$B$3:$B$12, $A5)This confirms the row label appears exactly once. For the header, use a matching count on the header row:
=COUNTIF(Rates!$C$2:$H$2, C$4)Then a single cell can test the whole block, for example by counting how many keys return something other than 1. A model reviewer can read that one cell and know every key resolved.
Worked example
You have the rate grid above in Rates!B2:E5. The row labels sit in B3:B5, the headers in C2:E2, and the values in C3:E5. In your output sheet, A5 holds "Operations" and C4 holds "FY25".
=INDEX(Rates!$C$3:$E$5, MATCH($A5, Rates!$B$3:$B$5, 0), MATCH(C$4, Rates!$C$2:$E$2, 0))The first MATCH returns 2, because Operations is the second label. The second MATCH returns 2, because FY25 is the second header. INDEX returns the cell in row 2 and column 2 of the body, which is 2.6%.
The nested form gives the same answer:
=XLOOKUP($A5, Rates!$B$3:$B$5, XLOOKUP(C$4, Rates!$C$2:$E$2, Rates!$C$3:$E$5))Copy either formula across the year columns and down the cost-center rows. Because of the mixed anchors, no edits are needed.
Summary
- A two-way lookup uses a row key and a column key to find one cell in a grid.
INDEXwith twoMATCHfunctions works in every Excel version and exposes both positions.- Nested
XLOOKUPis shorter and matches exactly by default. - Both builds depend on unique labels, matching data types, and ranges that line up with the body.
- Check keys with
COUNTIFand avoidIFERRORas a way to hide failures.
Exercise
A two-way lookup uses INDEX(Rates!$C$3:$H$12, MATCH($A5, Rates!$B$4:$B$13, 0), MATCH(C$4, Rates!$C$2:$H$2, 0)). It returns plausible numbers with no errors, but a reviewer says every value belongs to the wrong cost center. What is wrong, and how do you fix it?
Show answer
The label range starts at row 4 while the body starts at row 3, so MATCH counts positions from a different first row than INDEX does. Every result is shifted by one row. Change the label range to Rates!$B$3:$B$12 so it starts on the same row as the body and has the same number of rows.
Exercise
Write a check formula that returns 1 when the header in C$4 appears exactly once in Rates!$C$2:$H$2, and say what a result of 0 and a result of 2 would mean.
Show answer
=COUNTIF(Rates!$C$2:$H$2, C$4). A result of 0 means the header is missing, so the lookup would return #N/A. A result of 2 means the header is duplicated, so the lookup would silently use only the first match.