sumproduct using a range of conditions as opposed to one condition

doug firr

Board Regular
Joined
Mar 28, 2011
Messages
140
Hello

I need to sum the values in a range where that range is from april - august.

The months are numbered: jan=1, feb=2, march=3 etc.

I had a formula along the lines of:

=SUMPRODUCT((B5:B8503=2011)*(C5:C8503=4:8)*(H5:H8503))

This did not work.

Note the ideal "4:8" for months april - august. The intention being where column c contains numbers 4,5,6,7 and 8 then treat as true.

Is there a way to do this simply and elegantly - sumproduct for where a range of conditions are true?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hello

I need to sum the values in a range where that range is from april - august.

The months are numbered: jan=1, feb=2, march=3 etc.

I had a formula along the lines of:

=SUMPRODUCT((B5:B8503=2011)*(C5:C8503=4:8)*(H5:H8503))

This did not work.

Note the ideal "4:8" for months april - august. The intention being where column c contains numbers 4,5,6,7 and 8 then treat as true.

Is there a way to do this simply and elegantly - sumproduct for where a range of conditions are true?
One way...

Use cells to hold the criteria:

A1 = 2011
B1 = 4
C1 = 8

=SUMPRODUCT(--(B5:B8503=A1),--(C5:C8503>=B1),--(C5:C8503<=C1),H5:H8503)
 
Upvote 0
One way...

Use cells to hold the criteria:

A1 = 2011
B1 = 4
C1 = 8

=SUMPRODUCT(--(B5:B8503=A1),--(C5:C8503>=B1),--(C5:C8503<=C1),H5:H8503)
If you're using Excel 2007 or later use the SUMIFS function:

=SUMIFS(H5:H8503,B5:B8503,A1,C5:C8503,">="&B1,C5:C8503,"<="&C1)
 
Upvote 0
@firefly2012 that worked thanks a lot. Out of curiosity what does "+0" do between the brackets in the function? Never seen that before. Either way I followed your logic using "*" and that has worked and saved me time - many thanks! If I knew of a way to mark question as resolved I would. @Biff thanks too I just tried firefly's method 1st
 
Last edited:
Upvote 0
@firefly2012 that worked thanks a lot. Out of curiosity what does "+0" do between the brackets in the function? Never seen that before. Either way I followed your logic using "*" and that has worked and saved me time - many thanks! If I knew of a way to mark question as resolved I would. @Biff thanks too I just tried firefly's method 1st

Each conditional argument in the Sumproduct e.g:

(A1:A10=SomeValue)

returns an array (list) of True/False values dependent on whether the values in A1:A10 equal SomeValue.

Unfortunately, Sumproduct doesn't know how to treat lists of True/Falses without some additional help to convert them to 1s and 0s.

One such way of doing this is to add 0 (+0) on the basis that

True + 0 = 1
False + 0 = 0

Other ways you may see of achieveing this are -- and *1. Any mathematical operation will coerce the True/Falses to 1s and 0s.

This is why in your original it works by you mulitplying the conditional arrays together as True * True = 1 and and True/False * False = 0.


Don't worry about marking it solved - this forum doesn't support that facility :)
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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