A two-way lookup in Excel returns a value from the intersection of a specific row and column in a table. The most reliable modern method is XLOOKUP nested inside another XLOOKUP, or INDEX with two MATCH functions if you are on an older version. You need a table with unique row headers and unique column headers, and you need to know which Excel version you are using, because XLOOKUP is only available in Microsoft 365 and Excel 2021 and later.
What You'll Need
- A table of data with row labels down the left side and column labels across the top.
- Unique values in both the row headers and the column headers (duplicates will return the first match only).
- Excel 2021 or Microsoft 365 for
XLOOKUP; Excel 2019 or earlier for theINDEX/MATCHmethod. - Your lookup values (the row and column you want to search for) entered in separate cells, or typed directly into the formula.
Step-by-Step
- Set up your table cleanly. Put row labels in the first column (for example, product names) and column labels in the first row (for example, months). Leave no blank rows or columns inside the table, and do not merge cells. Merged cells break both lookup methods.
- Decide where the answer goes. Click the cell where you want the result. This is where the formula will live.
- Enter your two lookup values. In two separate cells, type the row label you want (e.g., "Widget A") and the column label you want (e.g., "March"). Referencing cells is better than typing values into the formula, because you can change them without editing the formula.
- Write the XLOOKUP method (Microsoft 365 / Excel 2021). The outer
XLOOKUPfinds the row, and the innerXLOOKUPfinds the column within that row. The pattern is:=XLOOKUP(row_value, row_headers, XLOOKUP(column_value, column_headers, data_range))
For example, if row headers are inA2:A10, column headers are inB1:M1, and the data block isB2:M10, and your lookup values are inP1(row) andP2(column):=XLOOKUP(P1, A2:A10, XLOOKUP(P2, B1:M1, B2:M10)) - Press Enter and check the result. The formula should return the value at the crossing point. If it returns
#N/A, one of your lookup values does not exactly match a header (check for trailing spaces). - Write the INDEX/MATCH method (older Excel). This does the same job with two
MATCHcalls feedingINDEX:=INDEX(B2:M10, MATCH(P1, A2:A10, 0), MATCH(P2, B1:M1, 0))
The firstMATCHreturns the row number, the second returns the column number, andINDEXpulls the value at that intersection. The0at the end of eachMATCHmeans exact match, which is what you want. - Lock the ranges if you will copy the formula. Select the ranges in the formula and press F4 to add dollar signs (e.g.,
$A$2:$A$10), so the references do not shift when you drag the formula down or across. - Test with a different row and column. Change the lookup values and confirm the result updates correctly. Try a value that does not exist to see how the formula behaves (it will show
#N/Aunless you add error handling). - Add error handling (optional but recommended). Wrap the formula in
IFERRORto show a friendly message instead of an error:=IFERROR(XLOOKUP(P1, A2:A10, XLOOKUP(P2, B1:M1, B2:M10)), "Not found")
Common Mistakes
- Mismatched range sizes. The row headers range, the column headers range, and the data block must line up. If row headers are
A2:A10(9 rows), the data block must also have 9 rows. A mismatch returns#N/Aor a wrong value. - Including the header row in the data range. The data block should start one row below the column headers and one column to the right of the row headers. Including headers shifts every result by one.
- Using approximate match by mistake. In
MATCH, omitting the0makes it approximate, which can return the wrong row for unsorted data. Always use0for exact match. - Trailing spaces in headers. "March " and "March" are different to Excel. Use
TRIMon your lookup values or clean the headers. - Duplicate headers. If two rows are both labelled "Widget A", the formula returns the first one only. Make headers unique.
- Forgetting to lock ranges before copying. Without dollar signs, copying the formula down shifts the ranges and returns wrong values or errors.
Tips
- Convert your table to an official Excel Table (select it and press Ctrl+T). Then you can refer to columns by name, and the ranges expand automatically when you add rows.
- Use
XLOOKUPwhere available: it is shorter, does not need column counting, and defaults to exact match. - Put your two lookup values in named cells (Formulas > Define Name) so the formula reads like
=XLOOKUP(Product, Products, XLOOKUP(Month, Months, Data)). - If you need to look up text rather than numbers, the same formulas work; just make sure the lookup value is text, not a number stored as text.
- For a quick visual check, use conditional formatting to highlight the row and column of the matched value.
Troubleshooting
- Formula returns
#N/A: The lookup value does not exactly match any header. Check for extra spaces, different case (Excel lookups are not case-sensitive by default, so case is rarely the issue), or numbers stored as text. Use=TRIM(P1)to test. - Formula returns
#REF!: A range reference is invalid, often because rows or columns were deleted after the formula was written. Check each range still exists. - Formula returns
#VALUE!: One of the arguments is the wrong type, for example a range where a single value is expected. Re-check the order of arguments. - Result is off by one row or column: Your data range includes the header row or column. Adjust the start of the range.
- Result is correct for one lookup but wrong for another: Likely duplicate headers or approximate match. Make headers unique and confirm the
0inMATCH. XLOOKUPis not recognised: Your Excel version does not support it. Use theINDEX/MATCHmethod instead.
Frequently Asked Questions
Can I do a two-way lookup without XLOOKUP?
Yes. INDEX with two MATCH functions works in all modern Excel versions and is the standard fallback for Excel 2019 and earlier.
Does a two-way lookup work with text values?
Yes. Both XLOOKUP and INDEX/MATCH return whatever is at the intersection, whether text, number, or date.
Why does my formula return the first match when there are duplicates?
Excel lookups stop at the first match. To handle duplicates, make your headers unique or use a helper column that combines the row and column labels into a single unique key.
Can I use a two-way lookup across two different sheets?
Yes. Reference the ranges with the sheet name, for example Sheet2!A2:A10. The same rules about matching range sizes apply.
What is the difference between XLOOKUP and INDEX/MATCH for two-way lookups?
XLOOKUP is shorter and defaults to exact match, so it is less error-prone. INDEX/MATCH is compatible with older versions and gives you more control over the order of arguments.
Can I make the lookup case-sensitive?
Standard XLOOKUP and MATCH are not case-sensitive. For case-sensitive matching you need a different approach, such as SUMPRODUCT with EXACT, which is more advanced and not covered by the basic two-way lookup.