In Excel, I have data like this:
I want to put together a formula that counts the rows where Col1 is "a" or "b" and Col2 is "c" or "d". I highlighted the rows that should be included. The result should be 4.
I've tried a few options:
(1) Using COUNTIFS with multiple possible values. This returns 2 instead of 4. I don't know why
=SUM(COUNTIFS(A2:A7,{"a","b"},B2:B7,{"c","d"}))
(2) USING COUNTIFS which each possible combination of filters. This works, but the formula is long. And the size of it will explode if I add more filters with more possible values
=COUNTIFS(A2:A7,"a",B2:B7,"c")+COUNTIFS(A2:A7,"a",B2:B7,"d")+COUNTIFS(A2:A7,"b",B2:B7,"c")+COUNTIFS(A2:A7,"b",B2:B7,"d")
(3) ChatGPT answer. This returns 0 instead of 4. I got this from ChatGPT. It gave me a few different formulas that would return either 0 or 1.
=SUMIFS(C2:C7, A2:A7, {"a","b","c","d","e","f","g"}, B2:B7, {"b","c","d","e","f","g","h"})
I'd also like a formula that sums column "N" for rows that pass this filtering. Can someone give me a hand with this?
Here's the data as text
Col1 Col2 N
b c 1
a c 2
a d 3
b d 4
b e 5
c e 6