Simplified data in columns A, B and 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? (ie. result is 2). Was thinking about COUNTIFS
but can't seem to get the formula right :(
You can't do this with a single COUNTIFS
, because conditions in COUNTIFS
are AND
, not OR
. You can do it with multiple COUNTIFS
, or an Array Formula (not recommended - that's a bit overkill for this case)
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.
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
.
=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
As an Array Formula (using SUMPRODUCT
instead of SUM
, because then we don't need to use Ctrl + Shift + Enter ), for reference:
=SUMPRODUCT(--($A:$A="X")*--(--($B:$B="Y")+($C:$C="Y")>0))
(The >0
is so that the OR ( +
) doesn't double-count)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.