Skip to content
SheetFluent

XLOOKUP and INDEX MATCH with multiple criteria in Excel

SheetFluent team · · 6 min read

Join the conditions into one value, then look that up. Add a helper column that combines the two columns, =A2&"|"&B2, and look up the combined value: =XLOOKUP(G1&"|"&G2,D2:D7,C2:C7). The helper column works in every version of Excel and in Google Sheets. In Excel 2019 or earlier, use INDEX and MATCH in place of XLOOKUP: =INDEX(C2:C7,MATCH(G1&"|"&G2,D2:D7,0)). In Excel 365 and Excel 2021 you can also skip the helper column with =XLOOKUP(1,(A2:A7=G1)*(B2:B7=G2),C2:C7).

Why one condition isn't enough

A normal lookup finds the first row that matches one value. Picture a stock list where each item comes in sizes S, M and L. =XLOOKUP("Cap",A2:A7,C2:C7) finds the first Cap row and returns its units, whatever the size. If you wanted Cap in size M, you get the wrong number, and no error tells you so.

What you need is the row where the item is Cap and the size is M. There are three good ways to do that.

Method 1: a helper column

The simplest method turns two conditions into one. If a column holds Cap|M, Cap|S and so on, then looking up Cap|M is an ordinary lookup.

1. Insert a column next to your data and call it Key. Here it's column D.

2. In D2, join the item and the size with a separator: =A2&"|"&B2. The & joins text. For Cap in size M the result is Cap|M.

3. Fill the formula down to the last row.

4. Put the two things you're looking for in cells of their own, for example G1 (item) and G2 (size).

5. Look up the joined value in the Key column: =XLOOKUP(G1&"|"&G2,D2:D7,C2:C7). Read it as "join the item and size I want, find that in the Key column, and return the units from the same row".

Why the |? Without a separator, different pairs can join into the same text. "AB" and "C" give "ABC", and so do "A" and "BC". A character that never appears in your data keeps the pairs apart. Any rare character works; just use the same one in the helper column and in the lookup.

The helper column can sit at the far right, and you can hide it if it gets in the way. It must cover the same rows as the column you return from.

XLOOKUP is in Excel 365, Excel 2021 and later, and Google Sheets. In Excel 2019 or earlier, use the INDEX MATCH version below with the same helper column.

=XLOOKUP(G1&"|"&G2,D2:D7,C2:C7)

See also: Look up in any direction with XLOOKUP

The same with INDEX MATCH

If your version of Excel doesn't have XLOOKUP, use INDEX and MATCH with the same helper column: =INDEX(C2:C7,MATCH(G1&"|"&G2,D2:D7,0)).

MATCH finds which row of the Key column holds Cap|M and returns its position, such as 4. INDEX then returns the 4th value from C2:C7.

Don't forget the 0 at the end of MATCH. It means "exact match only". Without it, MATCH assumes the list is sorted and can return a wrong row with no warning.

VLOOKUP works too, but only if the Key column is to the left of the column you want back, because VLOOKUP searches the first column of the range and returns from columns to its right. With Key in D and Units in C, as here, use XLOOKUP or INDEX MATCH.

Method 2: no helper column (Excel 365, Excel 2021 and Google Sheets)

Newer versions can test conditions across a whole range at once, which removes the need for a helper column.

=XLOOKUP(1,(A2:A7=G1)*(B2:B7=G2),C2:C7)

Here's how to read it. (A2:A7=G1) checks every item against G1 and gives a list of TRUE and FALSE values. (B2:B7=G2) does the same for size. Multiplying the two lists turns TRUE into 1 and FALSE into 0, so a row gives 1 only when both conditions are TRUE. XLOOKUP then looks for the first 1.

The INDEX MATCH version is =INDEX(C2:C7,MATCH(1,(A2:A7=G1)*(B2:B7=G2),0)). In Excel 2019 and earlier, finish it with Ctrl+Shift+Enter so Excel treats it as an array formula; it then shows curly braces around it. Excel 365 and Excel 2021 don't need that step. In Google Sheets, wrap either version in ARRAYFORMULA, which lets the multiplied conditions work across the whole range: =ARRAYFORMULA(XLOOKUP(1,(A2:A7=G1)*(B2:B7=G2),C2:C7)).

Add a third condition by multiplying in a third test in parentheses: *(C2:C7>10).

This method is tidy but harder to check. If the result looks wrong, test each condition in its own cell first. The helper column is easier to debug, and our practice grid uses it.

Method 3: SUMIFS, when the answer is a number

If the value you want is a number and each pair appears only once, SUMIFS gives the same answer with no helper column and no array math: =SUMIFS(C2:C7,A2:A7,G1,B2:B7,G2).

Read it as "add the units where the item is G1 and the size is G2". Because only one row matches, the sum is just that row's value.

Two warnings. If the pair appears twice, SUMIFS adds both rows and doesn't tell you. And if no row matches, it returns 0 and not an error, so a missing item looks like an item with zero stock. Use it only when you know each pair is unique.

See also: Add up with two conditions using SUMIFS

Which match do you get when there are several?

XLOOKUP and MATCH both return the first row that matches, counting from the top. If your list has two rows for Cap in size M (two deliveries, say), you only see the first one.

If you want the total across those rows, SUMIFS is the right tool, since adding them up is the point. If you want the most recent row, sort the data so the newest is at the top, or use XLOOKUP's sixth part, -1, which searches from the bottom up.

To check whether a pair appears more than once before you look it up, count it: =COUNTIFS(A2:A7,G1,B2:B7,G2). Anything above 1 means the lookup is picking one row out of several.

See also: How to find duplicates in Excel with COUNTIF

When the lookup returns #N/A

The pair doesn't exist. Check that the item really comes in that size.

Spaces or spelling. "Cap " with a trailing space won't match "Cap". Clean the data with TRIM, or build the key with =TRIM(A2)&"|"&TRIM(B2).

The helper column is out of date. If you added rows, fill the Key formula down to cover them.

Wrong ranges. The lookup range and the return range must be the same size and start on the same row.

To show a message in place of #N/A, XLOOKUP has a fourth part: =XLOOKUP(G1&"|"&G2,D2:D7,C2:C7,"Not found"). With INDEX MATCH, wrap it in IFERROR.

See also: Remove extra spaces with TRIM

Try it here

Type the formula into the answer cell, then press Enter or Check.

In B11, find the units for the item in B9 in the size in B10. Column D already joins item and size. Finish the formula.

ABCD
1ItemSizeUnitsKey
2ShirtS14Shirt|S
3ShirtM22Shirt|M
4CapS9Cap|S
5CapM17Cap|M
6ShirtL11Shirt|L
7CapL6Cap|L
8
9ItemCap
10SizeM
11Units=XLOOKUP(B9&"|"&B10, (answer cell)
Start practicing

Questions people ask

Can VLOOKUP use multiple criteria?

Not on its own. Add a helper column that joins the conditions, make it the first column of the range, and VLOOKUP the joined value.

Why do I need a separator like | in the helper column?

Without one, different pairs can join into the same text, such as "AB" plus "C" and "A" plus "BC". A separator that never appears in your data keeps every key unique.

Which method should I use?

The helper column if other people will read the sheet or you use an older Excel. The no-helper XLOOKUP if you're on Excel 365 or 2021 and want fewer columns. SUMIFS only for numbers where each pair appears once.

Does this work in Google Sheets?

Yes. The helper column method works as it is. For the no-helper versions, wrap the formula in ARRAYFORMULA so the multiplied conditions work across the whole range.

Keep practicing

Practice this in the full lesson: Look up with INDEX and MATCH