Reputation: 91
I need to count the number of cells in which the cells in "LIST A" appear in the set of values contained in column D AND the cells in "LIST B" do not appear in column E.
I am trying to use something like the following array formula, but so far have had limited success:
={SUM(COUNTIFS(A2:A21,D2:D5,B2:B21,"<>"&E2:E3))}
Please note that the data contained in this example is different to the data in my real table. The real table is considerably longer and more complex than this table.
Any suggestions?
Upvotes: 1
Views: 6182
Reputation: 7979
just for your example the formula like in my comment will be enough
=SUMPRODUCT(COUNTIF(D2:D5,A2:A21)*NOT(COUNTIF(E2:E5,B2:B21)))
the problem ocures if you have multiple values you want to exclude. then you need to use a negative countif(s)
=SUMPRODUCT(1*NOT(COUNTIF(E2:E5,B2:B21)))
this would count all lines which contain anything of the exclude list. But the NOT
inside the sumproduct will switch it to opposite (the 1* is needed cus it would only contain bool which can't be count)
if you have column C with bool (true/false or 1/0) you can simply add that:
=SUMPRODUCT(COUNTIF(D2:D5,A2:A21)*NOT(COUNTIF(E2:E5,B2:B21))*C2:C21)
or also (C2:C21>12)
if that is what you need... but you also could include it to the include list (if A is A/B/E/F and C is (2/4/6)
=SUMPRODUCT(COUNTIFS(D2:D5,A2:A21,F2:F5,C2:C21)*NOT(COUNTIF(E2:E5,B2:B21)))
But every exclude needs its own countif (B is not X/Y and C is not 8/9/11)
=SUMPRODUCT(COUNTIFS(D2:D5,A2:A21)*NOT(COUNTIF(E2:E5,B2:B21))*NOT(COUNTIF(F2:F5,C2:C21))
As already said: Having formulas which return ""
may return false counts (keep that in mind)
Upvotes: 1
Reputation: 7762
Best to switch to SUMPRODUCT
in such cases:
=SUMPRODUCT(0+ISNUMBER(MATCH(A2:A21,D2:D5,0)),1-ISNUMBER(MATCH(B2:B21,E2:E5,0)))
Regards
Upvotes: 1