简体   繁体   中英

Excel CountIf Formula With OR

I was looking for a excel formula to do a task. Tried using Countif,Countifs. But with no luck. Any help is appreciated.
Task as below.

Type--------------Primary Color--------------Secondary Color
Car----------------Blue--------------------------Red
Bike--------------Black-------------------------White
Car---------------Blue--------------------------Blue

I need a formula which gives me a count of Cars having blue as their colour(Either Primary Or Secondary)

You can use following array formula (confirmed with Ctrl + Shift + Enter to calculate count of blue cars:

=SUM(N((B2:B4="Blue")+(C2:C4="Blue")>0)*(A2:A4="Car"))

or non array version:

=SUMPRODUCT(N((B2:B4="Blue")+(C2:C4="Blue")>0)*(A2:A4="Car"))

This part:

(B2:B4="Blue")+(C2:C4="Blue")>0

is an alternative way of expressing OR (not suitable for array formulas as it always returns a single value). N function converts boolean values to 0 and 1 .

Edit: updated the formulas to include condition for A column.

What about adding a column with the following

=IF(OR(B1="Blue", C1="Blue"), 1, 0)

and copy that down.

On another sheet you can sum that new entire column with

=SUM(D:D)

Of course you will have a worksheet reference to the other sheet attached to the SUM formula.

如果您不想执行数组公式,则可以只执行2个countifs公式(比数组公式更容易阅读)

=COUNTIFS(b8:b12,"Blue")+COUNTIFS(c8:c12,"Blue")

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