countif excel 具有 A 列或 B 列中的值

countif excel with value in column A or column B

我想在 Excel 中使用 COUNTIF,但我想计算 column V = yes OR column U = yes 的行数,所有其他条件都相同。

在 1 列中使用 or 很容易,例如 P4:P999 = "apple" or "orange",但是如何在多个列中使用 or

下面是一个 Excel 代码示例,可读性强。我找到的唯一解决方案是使用加法并重写整个代码,但我讨厌这个解决方案,因为它太长了。

SUM(COUNTIFS(
     P4:P9999,  {"apple", "orange"}, 
     B4:B9999, "potato",
     AF4:AF9999, "",
     V4:V9999,  "Yes"
    )
) + 
SUM(COUNTIFS(
     P4:P9999,  {"apple", "orange"},
     B4:B9999, "potato",
     AF4:AF9999,  "",
     U4:U9999,  "Yes"
   )
)

切换到 SUMPRODUCT:

=SUMPRODUCT(((P4:P9999 = "apple")+(P4:P9999 = "orange"))*(B4:B999="potato")*(LEN(AF4:AF999)=0)*((V4:V9999="Yes)+(U4:U9999="Yes")>0))