简体   繁体   English

当 Y 在 B 列或 C 列中时,计算 A 列中 X 的数量

[英]Count number of X in Column A when Y is in either Column B or C

Simplified data in columns A, B and C: A、B 和 C 列中的简化数据:

A | B | C
X |   | Y
  | Y |
X | Y |
Z |   | Y
X |   |  

How to count the number of X when the value of Y is present in column B or C?当 B 或 C 列中存在 Y 的值时,如何计算 X 的数量? (ie. result is 2). (即结果为 2)。 Was thinking about COUNTIFS but can't seem to get the formula right :(正在考虑COUNTIFS但似乎无法正确计算公式:(

You can't do this with a single COUNTIFS , because conditions in COUNTIFS are AND , not OR .您不能使用单个COUNTIFS执行此COUNTIFS ,因为COUNTIFS中的条件是AND ,而不是OR You can do it with multiple COUNTIFS , or an Array Formula (not recommended - that's a bit overkill for this case)可以使用多个COUNTIFS或数组公式(不推荐 - 在这种情况下有点矫枉过正)

You need to count up all the rows where Column A is X and Column B is Y , add all the rows where Column A is X and Column C is Y , and then decide of a row where Column A is X and both Column B and Column C are Y is possible and/or should be counted twice.你需要计算了所有的行,其中列AX列BY ,添加的所有行,其中列AXC列Y然后再决定一排,其中列AX列BC 列Y是可能的和/或应该计算两次。

If it is possible, but should not be double-counted, then you will need to subtract all the rows where Column A is X and Columns B and C are both Y .如果有可能,但应该被重复计算,那么你将需要减去所有,其中A列是行X列B和C都是Y

=COUNTIFS($A:$A,"X",$B:$B,"Y") + COUNTIFS($A:$A,"X",$C:$C,"Y") - COUNTIFS($A:$A,"X",$B:$B,"Y"",$C:$C,"Y")

If it can't be in both, or you want that to count as 2 rows instead of 1, then you don't need the third COUNTIFS如果它不能同时存在,或者您希望将其计为 2 行而不是 1,那么您不需要第三个COUNTIFS

As an Array Formula (using SUMPRODUCT instead of SUM , because then we don't need to use Ctrl + Shift + Enter ), for reference:作为数组公式(使用SUMPRODUCT而不是SUM ,因为我们不需要使用Ctrl + Shift + Enter ),供参考:

=SUMPRODUCT(--($A:$A="X")*--(--($B:$B="Y")+($C:$C="Y")>0))

(The >0 is so that the OR ( + ) doesn't double-count) >0是为了使OR ( + ) 不会重复计算)

Because you never have a double-Y case, you can use:因为您从来没有双 Y 案例,所以您可以使用:

=SUMPRODUCT((A1:A5="X")*(B1:B5="Y"))+SUMPRODUCT((A1:A5="X")*(C1:C5="Y"))

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM