XLOOKUP 多条件查找:Excel 与 Google Sheets

XLOOKUP 只有一个查找值。要同时匹配两列,可以把两个键拼接成一个,或把两个条件相乘后再查找 1。Google Sheets 中这两种写法都需要 ARRAYFORMULA;去掉后本次测试返回 #VALUE!。West 与 Bolt 的金额,两种方法都返回 0.55。

本文目录

快速解答

XLOOKUP 只有一个查找值。要同时匹配两列,可以把两个键拼接成一个,或把两个条件相乘后再查找 1。Google Sheets 中这两种写法都需要 ARRAYFORMULA;去掉后本次测试返回 #VALUE!。West 与 Bolt 的金额,两种方法都返回 0.55。

=XLOOKUP(F2&"|"&G2, ARRAYFORMULA(A2:A6&"|"&B2:B6), D2:D6)
=XLOOKUP(1, ARRAYFORMULA((A2:A6=F2)*(B2:B6=G2)), D2:D6)

检查要点

拼接时建议加入数据中不会出现的分隔符(例如竖线),以免不同组合连成相同字符串。查找不存在的 East 与 Bolt 时,第四参数返回 not found。默认返回第一条匹配;search_mode 为 -1 时,West 与 Bolt 的负责人从 Ben 变成后来的 Cara。

边界与兼容性

需要所有匹配行时改用 FILTER。本次测试在展开区域为空时返回金额 0.55 与 0.60,以及 Ben 与 Cara;下方已有内容时会出现 #REF!。INDEX/MATCH 配合同样的条件数组也可得到 0.55,MATCH 的第三参数必须是 0。

完整英文示例、公式与作者备注

Tested in: Live formulas in Google Sheets, November 12, 2026. Microsoft’s XLOOKUP documentation describes array arguments in Excel 365; those unwrapped array forms were not re-tested in a desktop Excel workbook on this date.

Which versions this applies to

  • Excel for Microsoft 365, Excel 2021 and Excel 2024: XLOOKUP can take array expressions for the lookup and return ranges. You will often see =XLOOKUP(F2&G2, A2:A6&B2:B6, D2:D6) written without ARRAYFORMULA. Confirm that form in your own Excel file; it returned #VALUE! in Google Sheets until ARRAYFORMULA was added.
  • Excel 2019 and earlier: No XLOOKUP. Use INDEX/MATCH with the same boolean array, entered as an array formula in older Excel, or a helper column.
  • Google Sheets: XLOOKUP is available. Wrap the combined lookup array in ARRAYFORMULA, as in the formulas above.

The sample list

RegionProductRepAmount
EastWidgetAnn12.50
EastGasketAnn4.10
WestBoltBen0.55
WestWasherBen0.20
WestBoltCara0.60

West/Bolt appears twice, which is useful later: XLOOKUP returns the first match unless you change search_mode. F2=West, G2=Bolt, F3=East, G3=Widget, and F4=East, G4=Bolt (a pair that is not in the list).

Method 1: Concatenate the two keys

Join the two lookup values, and join the two columns in the same way:

=XLOOKUP(F2&"|"&G2, ARRAYFORMULA(A2:A6&"|"&B2:B6), D2:D6)

That returned 0.55 for West/Bolt and 12.5 for East/Widget. The helper keys themselves spilled as East|Widget, East|Gasket, West|Bolt, and so on.

A missing pair gets #N/A unless you supply the fourth argument:

=XLOOKUP(F4&"|"&G4, ARRAYFORMULA(A2:A6&"|"&B2:B6), D2:D6, "not found")

East/Bolt is not in the list; this returned not found.

The delimiter matters. Joining with no separator (F2&G2 and A2:A6&B2:B6) also returned 0.55 and 12.5 on this particular list, because no two-column pair produced the same string as a different pair. That will not always be true. East + Bolton and EastB + olton would collide. A character that does not appear in the data, such as |, avoids that.

Without ARRAYFORMULA, =XLOOKUP(F2&G2, A2:A6&B2:B6, D2:D6) returned #VALUE! in this Sheets file. The & on two ranges does not automatically produce a column of keys unless you wrap it.

Method 2: Multiply two TRUE/FALSE tests

Each test produces TRUE or FALSE. Multiplying them gives 1 only on rows where both are true, and 0 everywhere else. XLOOKUP then looks for the 1:

=XLOOKUP(1, ARRAYFORMULA((A2:A6=F2)*(B2:B6=G2)), D2:D6)

This also returned 0.55 for West/Bolt. Without ARRAYFORMULA it returned #VALUE!, the same as the unwrapped concatenate form.

This method is easier to extend to three conditions: add another *(C2:C6=H2). It also avoids the delimiter question, because nothing is being concatenated.

INDEX/MATCH uses the same boolean array. This returned 0.55 as well:

=INDEX(D2:D6, MATCH(1, ARRAYFORMULA((A2:A6=F2)*(B2:B6=G2)), 0))

The 0 in MATCH is required so the 1 is an exact match, not an approximate one. That trap is covered in XLOOKUP vs INDEX MATCH vs VLOOKUP.

First match, last match, or every match

Default XLOOKUP, and MATCH, return the first row that qualifies. West/Bolt has Ben at 0.55 and later Cara at 0.60. Looking up the rep with search_mode omitted returned Ben. Asking XLOOKUP to search from the bottom returned Cara:

=XLOOKUP(1, ARRAYFORMULA((A2:A6="West")*(B2:B6="Bolt")), C2:C6)
=XLOOKUP(1, ARRAYFORMULA((A2:A6="West")*(B2:B6="Bolt")), C2:C6, "none", 0, -1)

If you need every matching row, XLOOKUP is the wrong tool. FILTER returned both amounts, 0.55 and 0.60, and both reps, Ben and Cara:

=FILTER(D2:D6, (A2:A6=F2)*(B2:B6=G2))
=FILTER(C2:C6, (A2:A6="West")*(B2:B6="Bolt"))

Leave empty cells under the formula. When this FILTER was first placed in a column that already had values in the cells below, Sheets returned #REF! (array result was not expanded) instead of the two amounts. That collision is the same class of error described in Fix “Array Result Was Not Expanded Because It Would Overwrite Data”.

A helper column is still valid

If you do not want ARRAYFORMULA in the lookup itself, add a key column:

=A2&"|"&B2

Fill it down, then run a normal XLOOKUP on that column. The math is the same as method 1; the work is just visible in the sheet. This is often the right choice when other people will edit the file, or when the file has to open in an Excel version that is awkward with arrays.

Excel vs. Google Sheets

ApproachGoogle Sheets (tested 12 Nov 2026)Excel 365 (from Microsoft’s XLOOKUP docs)
Concatenate two columns inside XLOOKUPNeeds ARRAYFORMULA; without it, #VALUE!Commonly written without ARRAYFORMULA
Boolean tests multiplied inside XLOOKUPNeeds ARRAYFORMULA; without it, #VALUE!Often written as (A2:A6=F2)*(B2:B6=G2) directly
search_mode -1 for the last matchWorked (Cara rather than Ben)Documented for XLOOKUP
FILTER for every matchReturned 0.55 and 0.60 when the spill area was emptyFILTER is available in Excel 365; argument order differs slightly

Argument separators follow the spreadsheet locale (comma vs semicolon).

Common mistakes

  1. Forgetting ARRAYFORMULA in Google Sheets. Both unwrapped forms returned #VALUE! here. That error is easy to misread as a bad lookup value; it is the array expression, not the SKU.
  2. Concatenating without a delimiter. It worked on this short list and will eventually collide on a real one. Use | or another character that does not appear in the data.
  3. Leaving MATCH’s third argument off. Approximate MATCH can return the wrong row and no error. Always pass 0 here.
  4. Expecting XLOOKUP to return every West/Bolt row. It returns one. Use FILTER for the full set, and keep the spill range empty.
  5. Using IFERROR to hide a #VALUE! from a missing ARRAYFORMULA. You want to see that error until the array is wrapped. IFERROR vs IFNA covers which wrapper hides which error.

FAQ

Can XLOOKUP use two conditions?

Not as two separate arguments. Combine the conditions first, either by concatenating the keys or by multiplying TRUE/FALSE tests, then look up that single result. Both methods returned 0.55 for West/Bolt in this test.

Why do I get #VALUE! from a two-column XLOOKUP in Google Sheets?

If you wrote A2:A6&B2:B6 or (A2:A6=F2)*(B2:B6=G2) without ARRAYFORMULA, that is the likely cause. Both unwrapped forms returned #VALUE! here; adding ARRAYFORMULA produced the amount.

How do I return the last row that matches both conditions?

Set XLOOKUP’s search_mode to -1. For West/Bolt, that changed the rep from Ben (first row) to Cara (later row).

Should I use FILTER instead?

Use FILTER when you want every matching row. It returned both West/Bolt amounts, 0.55 and 0.60. Use XLOOKUP when you want one value, optionally the first or the last.

What if one of the pair is missing?

XLOOKUP returns #N/A. Add the fourth argument for a label, as in the East/Bolt test, which returned not found. If #N/A appears when you can see the pair, check spaces and text-versus-number mismatches; those causes are in XLOOKUP Returns #N/A Even Though the Value Exists.

Live-test findings

All numeric results above come from one Google Sheets file dated November 12, 2026. Concatenate and boolean XLOOKUP both returned 0.55 for West/Bolt and required ARRAYFORMULA (#VALUE! without it). A | delimiter produced the same 0.55 and 12.5 results, and not found for East/Bolt. search_mode -1 changed the West/Bolt rep from Ben to Cara. FILTER returned 0.55 and 0.60, and Ben and Cara, once the spill range was empty.

Sources

Oscar

专注电子表格公式与排错;具体测试环境和待验证事项见各篇文章。

Tested in Google Sheets, November 12, 2026. Excel array behavior is taken from Microsoft documentation and was not re-tested in a desktop Excel workbook on this date..

本主题下一篇:查找与条件求和 比较两列并找出缺失值:Excel 与 Google Sheets