简体   繁体   中英

How can I use COUNTIFS for multiple criteria?

I want to be able to use the COUNTIFS formula for multiple criteria.

For example:

1,Banana
2,Orange
1,Banana
2,Orange

I want to use COUNTIFS to count how many occurrences of 1 is associated with banana and how many times 2 is associated with orange .

I'm thinking of =COUNTIFS(A:A,1,B:B,"Banana")+=COUNTIFS(A:A,2,B:B,"Orange")

This would supposedly equal 4, but I know that formula is wrong and I don't know how to format it.

If this is not possible, then I'd have to use two of the same formulas and add them together, but I'm looking for a better way and just use one formula.

How do I go about this problem, any help would be greatly appreciated.

Thank you.

EDIT: =COUNTIFS(A:A,1,B:B,"Banana",A:A,2,B:B,"Orange") returns 0 for some reason, why is that?

You can try SUMPRODUCT function instead: =SUMPRODUCT(((B:B="Orange")+(B:B="Banana"))*(A:A=1))

To add additional criteria value, you need to add it to the rest, for example - adding Apples criteria: =SUMPRODUCT(((B:B="Orange")+(B:B="Banana")+(B:B="Apple"))*(A:A=1))

Similar logic needs to be used to add another criteria range, for example: =SUMPRODUCT(((B:B="Orange")+(B:B="Banana")) (A:A=1) (C:C="X"))

Hope it helped.

EDIT: Just saw question adjustment. In that case you should use following logic: =SUMPRODUCT((B:B="Orange") (A:A=1)+(B:B="Banana") (A:A=2))

你的公式应该是

=COUNTIFS(A:A,1,B:B,"Banana")+COUNTIFS(A:A,2,B:B,"Orange")

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.

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