Sumproduct Help

karldugan

New Member
Joined
May 10, 2016
Messages
47
Hello Excelers,

I think a sumproduct is the solution but honestly I never understand how they work :( If sumproduct does work, would you mind explaining how the formula is built/how it is working?

I want to add up stage 1 - 4 if it is between a certain date, say 01/09/2022 and 30/09/2022. I could use a repeating sumifs, but I'm sure I've seen sumproduct do the same thing better.

Thanks in advance - Karl.

Stage 1Stage 2Stage 3Stage 4Stage 1 DateStage 2 DateStage 3 DateStage 4 Date
570​
3180​
9073​
1772​
07/09/2022​
07/10/2022​
09/11/2022​
05/12/2022​
1834​
5458​
5469​
7875​
12/03/2022​
07/04/2022​
07/05/2022​
13/06/2022​
4294​
8165​
8477​
2701​
30/07/2022​
30/08/2022​
21/09/2022​
08/10/2022​
3019​
9472​
2569​
7433​
14/04/2022​
16/05/2022​
30/05/2022​
05/07/2022​
9662​
5729​
7187​
7461​
19/04/2022​
10/05/2022​
11/06/2022​
14/07/2022​
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Is this what you mean?

Book1
ABCDEFGHIJKL
1Stage 1Stage 2Stage 3Stage 4Stage 1 DateStage 2 DateStage 3 DateStage 4 DateStart DateEnd DateResult
25703180907317729/7/202210/7/202211/9/202212/5/20229/1/20229/30/20229047
318345458546978753/12/20224/7/20225/7/20226/13/2022
442948165847727017/30/20228/30/20229/21/202210/8/2022
530199472256974334/14/20225/16/20225/30/20227/5/2022
696625729718774614/19/20225/10/20226/11/20227/14/2022
Sheet1
Cell Formulas
RangeFormula
L2L2=SUMPRODUCT(--($E$2:$H$6>=J2),--($E$2:$H$6<=K2),$A$2:$D$6)
 
Upvote 0
Solution
Hi @Domenic

Will it cause any error if we don't put "--"?

Book3
ABCDEFGHI
1Stage 1Stage 2Stage 3Stage 4Stage 1 DateStage 2 DateStage 3 DateStage 4 Date
25703180907317729/7/202210/7/202211/9/202212/5/2022
318345458546978753/12/20224/7/20225/7/20226/13/2022
442948165847727017/30/20228/30/20229/21/202210/8/2022
530199472256974334/14/20225/16/20225/30/20227/5/2022
696625729718774614/19/20225/10/20226/11/20227/14/2022
7
8
9Start DateEnd Date
109/1/20229/30/2022
11Total9047
12
13
14
Sheet2
Cell Formulas
RangeFormula
B11B11=SUMPRODUCT(A2:D6*(E2:H6>=A10)*(E2:H6<=B10))
 
Upvote 0
Is this what you mean?

Book1
ABCDEFGHIJKL
1Stage 1Stage 2Stage 3Stage 4Stage 1 DateStage 2 DateStage 3 DateStage 4 DateStart DateEnd DateResult
25703180907317729/7/202210/7/202211/9/202212/5/20229/1/20229/30/20229047
318345458546978753/12/20224/7/20225/7/20226/13/2022
442948165847727017/30/20228/30/20229/21/202210/8/2022
530199472256974334/14/20225/16/20225/30/20227/5/2022
696625729718774614/19/20225/10/20226/11/20227/14/2022
Sheet1
Cell Formulas
RangeFormula
L2L2=SUMPRODUCT(--($E$2:$H$6>=J2),--($E$2:$H$6<=K2),$A$2:$D$6)
That's the one!

Why do you have to put two minuses in front of the criteria though? Could you explain how it works as I never really understand sumproduct :( thank you for the help too though!
 
Upvote 0
Data A2:H6
Formula
Excel Formula:
=SUMPRODUCT(($E$2:$H$6>=A9)*($E$2:$H$6<=B9)*$A$2:$D$6)

Stage 1Stage 2Stage 3Stage 4Stage 1 DateStage 2 DateStage 3 DateStage 4 Date
12.003.004.0007-09-202207-10-202209-11-202205-12-2022
12.003.004.0012-03-202207-04-202207-05-202213-06-2022
12.003.004.0030-07-202230-08-202221-09-202208-10-2022
12.003.004.0014-04-202216-05-202230-05-202205-07-2022
12.003.004.0019-04-202210-05-202211-06-202214-07-2022
A9B9
01-09-2022​
30-09-2022​
=SUMPRODUCT(($E$2:$H$6>=A9)*($E$2:$H$6<=B9)*$A$2:$D$6)
 
Upvote 0
@karldugan, @Sufiyan97

You'll notice that the formula . . .

Excel Formula:
=SUMPRODUCT(--($E$2:$H$6>=J2),--($E$2:$H$6<=K2),$A$2:$D$6)

. . . uses the comma syntax. And you'll notice that it contains three arguments...

VBA Code:
--($E$2:$H$6>=J2)  ===> first argument
--($E$2:$H$6<=K2) ===> second argument
$A$2:$D$6  ===> third argument

($E$2:$H$6>=J2) returns an array of TRUE and FALSE. However, since the comma syntax requires numerical values, and not logical values, the double negative ( --- ) is used to coerce those values into their numerical equivalent, which would be 1 and 0, respectively. The same thing applies to --($E$2:$H$6<=K2).

So each element from the first argument is multiplied by its corresponding elements in the second and third argument. Then the values from the resulting array is summed.

You can see how the evaluation takes place by selecting the cell containing the formula and then clicking on Evaluate Formula (Ribbon >> Formulas tab >> Formula Auditing group).

With the following syntax...

Excel Formula:
=SUMPRODUCT(($E$2:$H$6>=J2)*($E$2:$H$6<=K2)*($A$2:$D$6))

...there's no need to coerce TRUE and FALSE values into their numerical equivalents. Those values are automatically converted to their numerical equivalent when multiplied.

Note, however, the comma syntax is more efficient.

Hope this helps!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,737
Messages
6,180,653
Members
452,992
Latest member
TokugawaIesuma

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