SUMIF Formula including OR

garymu16

Board Regular
Joined
Sep 15, 2006
Messages
139
Dear All,

How do I modify my formula (below) to include an OR statement?

=SUMIF(I4:I20,"Core",G4:G20)

I need something like this:

=SUMIF(I4:I20,"Core" or "Existing",G4:G20)

I know this will no-doubt be embarassingly easy but I can't get my head around it.

Thx in advance
Gary
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Simple way:

=SUMIF(I4:I20,"Core",G4:G20)+SUMIF(I4:I20,"Existing",G4:G20)

Another way:

=SUM(IF(OR(I4:I20="Core",I4:I20="Existing"),G4:G20,0))
entered using Ctrl+Shift+Enter

Probably about 10 other ways as well....:-)
 
Upvote 0
yet another.... or:

Code:
=SUM(SUMIF(I4:I20,{"Core","Existing"},G4))
 
Upvote 0
Colin

I understand this similar method:

=SUMPRODUCT(SUMIF(I4:I20,{"core";"existing"},G4:G20))

But your formula baffles me. :confused:
Why does it work?

The Evaluate Formula does little to explain it.
 
Upvote 0
Hi Jon

This bit:
Code:
SUMIF(I4:I20,{"Core","Existing"},G4)
Gives a horizontal array of 2 totals, one has the SUM of all the "Core"s, the other has the SUM of all the "Existing"s. So something like {5,10}

Then SUM() adds them together to give 15.

Since {"Core","Existing"} is an inline array constant (ie. containing directly within the formula), the formula does not have to be CSE entered. (My definition would be that this is already an "Array Formula".)

Conversely, if you were to use a named array constant, MyArray, where MyArray is defined as:
Code:
MyArray ={"Core","Existing"}
Then this formula would have to be CSE entered, I think because 'MyArray' is like a pointer to the names table, you have to tell Excel to treat it like an array:
Code:
=SUM(SUMIF(I4:I20,MyArray,G4))   'CSE entered
'or
=SUMPRODUCT(SUMIF(I4:I20,MyArray,G4))


So then comes the $1M question... which formula is best here? My guess would be Andrew's =SUMIF(I4:I20,"Core",G4:G20)+SUMIF(I4:I20,"Existing",G4:G20). But if lots of conditions then it becomes unwieldly - I've not tested efficiency between yours and mine, I suspect =SUMPRODUCT((I4:I20="core")+(I4:I20="existing"),G4:G20) might just edge it, but I'm not sure without running some tests. One of the formula experts here will know.

HTH
Colin
 
Last edited:
Upvote 0
What you don't mention, Colin, is that you specified the "sum range" as just G4.

SUMIF always uses a SUM range the same size as the first range, the top left cell of the sum range used will be the same as the top left of the range actually specified. That means the same range is summed even if you specifiy the range as G4, G4:G10000 or even G4:IV4.

Edit: this version could be a contender in the speed stakes.....

=SUMPRODUCT(--ISNUMBER(MATCH(I4:I20,{"core","existing"},0)),G4:G20)
 
Last edited:
Upvote 0
Hi Colin

Thanks for your explanation. :)

So from my observation Excel will know to handle the entire 'sum' array size even though you have only made reference to a single cell in the sum range (G4). So that's something new to me. Thanks.

Your explanation of using inline array completes the explanation for me. I have repeatedly used the SUMPRODUCT method (as per my previous post) despite using inline array. So now I know I can simply use SUM. :)

Thanks again!

Edit: Just noticed Barry's post. Thanks for your explanation on the sum range.
 
Upvote 0
Very true, Barry, I was concentrating too hard on explaining why it doesn't need to be CSE entered or need to be wrapped by SUMPRODUCT(). Speaking of formula experts, do you have an opinion on
Code:
=SUM(SUMIF(I4:I20,{"Core","Existing"},G4))
vs
Code:
=SUMPRODUCT((I4:I20="core")+(I4:I20="existing"),G4:G20)
?



I know that
Code:
=SUMPRODUCT(--ISNUMBER(MATCH(I4:I20,{"core","existing"},0)),G4:G20)
will be slower than Jon's SUMPRODUCT() formula using +, although again it is more easily extendable if the conditions increase.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,849
Members
452,948
Latest member
UsmanAli786

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