SUMIFS using an OR operator

miconian

Well-known Member
Joined
Aug 18, 2004
Messages
769
Basically, I'm using SUMIFS, and the final criterion could go one of two ways: either EMER or APPC are valid values.

Here's my formula:

=SUMIFS(Data2011[Net Amount],Data2011[Internet Site],A13,Data2011[Confidence %],"B",Data2011[Ad Unit],"EMER")

The last criterion, Data2011[Ad Unit],"EMER" is correct, but incomplete. Another valid criteria for [Ad Unit] should be "APPC".

So I'm trying to do something like this:

=SUMIFS(Data2011[Net Amount],Data2011[Internet Site],A13,Data2011[Confidence %],"B",Data2011[Ad Unit],"EMER" OR Data2011[Ad Unit],"APPC")

or perhaps:

SUMIFS(Data2011[Net Amount],Data2011[Internet Site],A13,Data2011[Confidence %],"B",OR((Data2011[Ad Unit],"EMER"),(Data2011[Ad Unit],"APPC"))

What am I missing?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
What if I wanted to combine two OR-statements in one AND-statement? For example, everything where the color is in {"red", "blue", "green"} and site is in {"CNN", "NBC"}.

Considering this dataset, I would thus expect a result of 25.

siteproductmoney
CNNred10
CNNblue15
CBSgreen25
NBCyellow67

<tbody>
</tbody>

A solution for either a SUM (=25) or a COUNT (resulting in =2) would help me.
 
Last edited:
Upvote 0
What if I wanted to combine two OR-statements in one AND-statement? For example, everything where the color is in {"red", "blue", "green"} and site is in {"CNN", "NBC"}.

Considering this dataset, I would thus expect a result of 25.

siteproductmoney
CNNred10
CNNblue15
CBSgreen25
NBCyellow67

<tbody>
</tbody>

A solution for either a SUM (=25) or a COUNT (resulting in =2) would help me.

1.
Rich (BB code):

=SUM(COUNTIFS(C2:C5,A2:A5,{"CNN";"NBC"},B2:B5,{"red","blue","green"}))
2.
Rich (BB code):

=SUM(SUMIFS(C2:C5,A2:A5,{"CNN";"NBC"},B2:B5,{"red","blue","green"}))

The foregoing cannot be done ad infinitum.

A more general approach:

3.
Rich (BB code):

=SUMPRODUCT(--ISNUMBER(MATCH(A2:A5,{"CNN","NBC"},0)),
  --ISNUMBER(MATCH(B2:B5,{"red","blue","green"},0)))
4.
Rich (BB code):

=SUMPRODUCT(C2:C5,--ISNUMBER(MATCH(A2:A5,{"CNN","NBC"},0)),
  --ISNUMBER(MATCH(B2:B5,{"red","blue","green"},0)))
 
Upvote 0
I deleted the C2:C5 you left in at the first code.
Works like a charm, thanks a million!

You prevented me from combining a LOT of countifs :')
 
Upvote 0
Things are getting complicated here. In another sum I'm trying to calculate I should only take dates that are in a certain range.

For example, this data range:
Higher than date(year(today()),month(today())-11),1)
AND
Lower than date(year(today()),month(today())-4),1)

Given the dataset:
Code:
site	product	money	date
CNN	red	10	01/05/2015
CNN	blue	15	12/12/2001
CBS	green	25	01/07/2014
NBC	yellow	67	01/07/2013

And this request:
Everything where the color is in {"red", "blue", "green"}
and site is in {"CNN", "NBC"}
and date is in the range defined above.

I would expect a result of 10. A count wouldn't help so much here, I would really need the sum.


Aladin, do you think you can help me out here again?
 
Last edited:
Upvote 0
Things are getting complicated here. In another sum I'm trying to calculate I should only take dates that are in a certain range.

For example, this data range:
Higher than date(year(today()),month(today())-11),1)
AND
Lower than date(year(today()),month(today())-4),1)

Given the dataset:
Code:
site    product    money    date
CNN    red    10    01/05/2015
CNN    blue    15    12/12/2001
CBS    green    25    01/07/2014
NBC    yellow    67    01/07/2013

And this request:
Everything where the color is in {"red", "blue", "green"}
and site is in {"CNN", "NBC"}
and date is in the range defined above.

I would expect a result of 10. A count wouldn't help so much here, I would really need the sum.


Aladin, do you think you can help me out here again?

Which period exactly are you interested in: From 1-Jan-2015 to 1-Aug-2015?
 
Upvote 0
Which period exactly are you interested in: From 1-Jan-2015 to 1-Aug-2015?

I see I arranged some comma's incorrectly, excuse me.
Yes, you are right.

In E2 enter:
Rich (BB code):

=DATE(YEAR(TODAY()),1,1)

In F2 enter:
Rich (BB code):

=DATE(YEAR(TODAY()),8,1)

In G2 enter:
Rich (BB code):
=SUMPRODUCT(C2:C5,--ISNUMBER(MATCH(A2:A5,{"CNN","NBC"},0)),
  --ISNUMBER(MATCH(B2:B5,{"red","blue","green"},0)),
  --($D$2:$D$5>=E2),--($D$2:$D$5<=F2))
 
Upvote 0

Forum statistics

Threads
1,215,372
Messages
6,124,532
Members
449,169
Latest member
mm424

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top