SUMPRODUCT array inconsistency

simchuck

New Member
Joined
Sep 27, 2011
Messages
14
I am having a problem with getting my formula to work correctly, hoping someone here can help me understand...

I have a dataset where each record consists of a start date, end date, and value. The start and end dates can fall anywhere within the month, and there could potentially be overlap in these records. My objective is to consolidate the values in to 'normalized' periods where the start and end dates coincide with the first and last days of the month.

I have the original start dates in column A, end dates in column B, and values in column C. The 'normalized' start is in column D, end in column E, and my consolidated value in column F, with the following formula (from cell F6 in this example):

Code:
 =SUMPRODUCT(($C$3:$C$7)*($A$3:$A$7<=E6)*($B$3:$B$7>=D6)*(IF($B$3:$B$7<E6,$B$3:$B$7,E6)-IF($A$3:$A$7>D6,$A$3:$A$7,D6)+1))

The idea is that I multiply the original value by the number of days for which this overlaps the normalized period, and sum these results for all of the original periods as appropriate. The problem is that the result from the formula doesn't give the correct value. I broke the formula down into steps to check this manually, and I do get the correct answer this way.

Below is a sample data set, followed by my breakdown calculations:

Code:
ACTUAL				NORMALIZED		
start	end		kWh/d	start	end	kWh
5/13/08	6/12/08		8.7	4/1/08	4/30/08	0
6/12/08	7/14/08		3.6	5/1/08	5/31/08	165
7/14/08	8/12/08		3.3	6/1/08	6/30/08	496
8/12/08	9/11/08		2.9	7/1/08	7/31/08	[B]242[/B]
9/11/08	10/10/08	3.3	8/1/08	8/31/08	221

Code:
[1]	[2]	[3]	[4]	[5]	[6]	[7]
8.7	TRUE	FALSE	6/12/08	7/1/08	-18	0
3.6	TRUE	TRUE	7/14/08	7/1/08	14	50.90909091
3.3	TRUE	TRUE	7/31/08	7/14/08	18	60
2.9	FALSE	TRUE	7/31/08	8/12/08	-11	0
3.3	FALSE	TRUE	7/31/08	9/11/08	-41	0
						[B]110.9090909[/B]

And these are the steps in the breakdown calculations:

Code:
[1]	 =($C$3:$C$7)		
[2]	 =($A$3:$A$7<=E6)		
[3]	 =($B$3:$B$7>=D6)		
[4]	 =IF($B$3:$B$7<E6,$B$3:$B$7,E6)		
[5]	 =IF($A$3:$A$7>D6,$A$3:$A$7,D6)		
[6]	 = [4] - [5] + 1		
[7]	 = [1] x [2] x [3] x [6]


The correct answer for cell F6 should be 110.9 as in my breakdown, but the formula gives 242. Any ideas on the source of this inconsistency?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Are your breakdown caculations manual or did you use excel functions?

> Seems to me, your formula for [4] has an error in the If "condition". There is no comparison operator.
> The results in the examples do not match your formula. They are showing either column B/E and your formula has column A/D
[4] =IF($B$3:$B$7D6,$A$3:$A$7,D6)

> The fourth parameter in your SumProduct formula is [4] instead of being [4]-[5]+1

These corrections may fix your sumproduct function.
 
Upvote 0
It seems that some of the code mysteriously disappears when I post my message, but I did review all of my formulas and they are as I had expected.

The display problem seems to be related to my 'less than' operators, so I replaced those operators in the formula below. This is the complete formula in cell F6:

Code:
=SUMPRODUCT(($C$3:$C$7)*($A$3:$A$7 [I]{less than or equal to}[/I] E6 {then use the value from the test range} {else use value in E6})*($B$3:$B$7 {greater than or equal to} D6 {then use the value from the test range} {else use value in D6})*(IF($B$3:$B$7 {less than} E6,$B$3:$B$7,E6)-IF($A$3:$A$7 {greater than} D6,$A$3:$A$7,D6)+1))

I did my breakdown in columns H:N. Here are the actual formulas -- only difference from the 'complete' formula above are the absolute row references for cells D6 and E6, since I needed to keep the references constant in my breakdown to focus on just the F6 (7/1-7/31) range.

Code:
H3:H7 =($C$3:$C$7)
I3:I7 =($A$3:$A$7 {less than or equal to} E$6 {then use the value from the test range} {else use value in E6})
J3:J7 =($B$3:$B$7 {greater than or equal to} D$6 {then use the value from the test range} {else use value in D6})
K3:K7 =IF($B$3:$B$7 {less than} E$6,$B$3:$B$7,E$6) 
L3:L7 =IF($A$3:$A$7 {greater than} D$6,$A$3:$A$7,D$6)
M3:M7 =(K3-L3+1)      <--- this formula is copied downward from cell M3
N3:N7 =H3*I3*J3*M3    <--- copied downward from N3

The sum of N3:N7 would be the correct value -- and I checked this separately using hand calculations to be sure.

I tried to run the formula evaluator, and it seems that the first IF function returns a single value in all of the rows, while the second returns different values as expected. Still doesn't make sense to me WHY it doesn't work.
 
Last edited:
Upvote 0
Here it works.

Look at this:

<b>Excel 2007</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #A6AAB6"><colgroup><col width="25px" style="background-color: #E0E0F0" /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /><col /></colgroup><thead><tr style=" background-color: #E0E0F0;text-align: center;color: #161120"><th></th><th>A</th><th>B</th><th>C</th><th>D</th><th>E</th><th>F</th><th>G</th><th>H</th><th>I</th><th>J</th><th>K</th><th>L</th><th>M</th><th>N</th><th>O</th><th>P</th><th>Q</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">1</td><td style="text-align: center;;">ACTUAL</td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style=";">NORMALIZED</td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">2</td><td style="text-align: center;;">start</td><td style="text-align: center;;">end</td><td style="text-align: center;;">kWh/d</td><td style="text-align: center;;">start</td><td style="text-align: center;;">end</td><td style="text-align: center;;">kWh</td><td style="text-align: center;;"></td><td style="text-align: center;;">[1]</td><td style="text-align: center;;">[2]</td><td style="text-align: center;;">[3]</td><td style="text-align: center;;">[4]</td><td style="text-align: center;;">[5]</td><td style="text-align: center;;">[6]</td><td style="text-align: center;;">[7]</td><td style="text-align: center;;">Result</td><td style="text-align: center;;">Result</td><td style="text-align: center;;">Result</td></tr><tr ><td style="color: #161120;text-align: center;">3</td><td style="text-align: center;;">5/13/2008</td><td style="text-align: center;;">6/12/2008</td><td style="text-align: center;;">8.7</td><td style="text-align: center;;">4/1/2008</td><td style="text-align: center;;">4/30/2008</td><td style="text-align: center;;">0</td><td style="text-align: center;;"></td><td style="text-align: center;;">8.7</td><td style="text-align: center;;">VERDADEIRO</td><td style="text-align: center;;">FALSO</td><td style="text-align: center;;">6/12/2008</td><td style="text-align: center;;">7/1/2008</td><td style="text-align: center;;">-18</td><td style="text-align: center;;">0.00</td><td style="text-align: center;;">109.80</td><td style="text-align: center;;">109.80</td><td style="text-align: center;;">109.80</td></tr><tr ><td style="color: #161120;text-align: center;">4</td><td style="text-align: center;;">6/12/2008</td><td style="text-align: center;;">7/14/2008</td><td style="text-align: center;;">3.6</td><td style="text-align: center;;">5/1/2008</td><td style="text-align: center;;">5/31/2008</td><td style="text-align: center;;">165</td><td style="text-align: center;;"></td><td style="text-align: center;;">3.6</td><td style="text-align: center;;">VERDADEIRO</td><td style="text-align: center;;">VERDADEIRO</td><td style="text-align: center;;">7/14/2008</td><td style="text-align: center;;">7/1/2008</td><td style="text-align: center;;">14</td><td style="text-align: center;;">50.40</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">5</td><td style="text-align: center;;">7/14/2008</td><td style="text-align: center;;">8/12/2008</td><td style="text-align: center;;">3.3</td><td style="text-align: center;;">6/1/2008</td><td style="text-align: center;;">6/30/2008</td><td style="text-align: center;;">496</td><td style="text-align: center;;"></td><td style="text-align: center;;">3.3</td><td style="text-align: center;;">VERDADEIRO</td><td style="text-align: center;;">VERDADEIRO</td><td style="text-align: center;;">7/31/2008</td><td style="text-align: center;;">7/14/2008</td><td style="text-align: center;;">18</td><td style="text-align: center;;">59.40</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">6</td><td style="text-align: center;;">8/12/2008</td><td style="text-align: center;;">9/11/2008</td><td style="text-align: center;;">2.9</td><td style="text-align: center;;">7/1/2008</td><td style="text-align: center;;">7/31/2008</td><td style="text-align: center;;">242</td><td style="text-align: center;;"></td><td style="text-align: center;;">2.9</td><td style="text-align: center;;">FALSO</td><td style="text-align: center;;">VERDADEIRO</td><td style="text-align: center;;">7/31/2008</td><td style="text-align: center;;">8/12/2008</td><td style="text-align: center;;">-11</td><td style="text-align: center;;">0.00</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">7</td><td style="text-align: center;;">9/11/2008</td><td style="text-align: center;;">10/10/2008</td><td style="text-align: center;;">3.3</td><td style="text-align: center;;">8/1/2008</td><td style="text-align: center;;">8/31/2008</td><td style="text-align: center;;">221</td><td style="text-align: center;;"></td><td style="text-align: center;;">3.3</td><td style="text-align: center;;">FALSO</td><td style="text-align: center;;">VERDADEIRO</td><td style="text-align: center;;">7/31/2008</td><td style="text-align: center;;">9/11/2008</td><td style="text-align: center;;">-41</td><td style="text-align: center;;">0.00</td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">8</td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">9</td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">10</td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">11</td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: center;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td><td style="text-align: right;;"></td></tr><tr ><td style="color: #161120;text-align: center;">12</td><td style="text-align: center;;">******</td><td style="text-align: center;;">******</td><td style="text-align: center;;">******</td><td style="text-align: center;;">******</td><td style="text-align: center;;">******</td><td style="text-align: center;;">******</td><td style="text-align: center;;">******</td><td style="text-align: center;;">******</td><td style="text-align: center;;">******</td><td style="text-align: center;;">******</td><td style="text-align: center;;">******</td><td style="text-align: center;;">******</td><td style="text-align: center;;">******</td><td style="text-align: center;;">******</td><td style="text-align: center;;">******</td><td style="text-align: center;;">******</td><td style="text-align: center;;">******</td></tr></tbody></table><p style="width:3.6em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #A6AAB6;border-top:none;text-align: center;background-color: #E0E0F0;color: #161120">Sheet3</p><br /><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: #FFFFFF" ><tr><td style="padding:6px" ><b>Worksheet Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: #FFFFFF;border-collapse: collapse; border-color: #A6AAB6"><thead><tr style=" background-color: #E0E0F0;color: #161120"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: #E0E0F0;color: #161120">H3</th><td style="text-align:left">=C3</td></tr><tr><th width="10px" style=" background-color: #E0E0F0;color: #161120">I3</th><td style="text-align:left">=A3<=E$6</td></tr><tr><th width="10px" style=" background-color: #E0E0F0;color: #161120">J3</th><td style="text-align:left">=B3>=D$6</td></tr><tr><th width="10px" style=" background-color: #E0E0F0;color: #161120">K3</th><td style="text-align:left">=IF(<font color="Blue">B3<E$6,B3,E$6</font>)</td></tr><tr><th width="10px" style=" background-color: #E0E0F0;color: #161120">L3</th><td style="text-align:left">=IF(<font color="Blue">A3>D$6,A3,D$6</font>)</td></tr><tr><th width="10px" style=" background-color: #E0E0F0;color: #161120">M3</th><td style="text-align:left">=K3-L3+1</td></tr><tr><th width="10px" style=" background-color: #E0E0F0;color: #161120">N3</th><td style="text-align:left">=H3*I3*J3*M3</td></tr><tr><th width="10px" style=" background-color: #E0E0F0;color: #161120">O3</th><td style="text-align:left">=SUM(<font color="Blue">N3:N7</font>)</td></tr></tbody></table></td></tr></table><br /><table width="85%" cellpadding="2.5px" rules="all" style=";border: 2px solid black;border-collapse:collapse;padding: 0.4em;background-color: #FFFFFF" ><tr><td style="padding:6px" ><b>Array Formulas</b><table cellpadding="2.5px" width="100%" rules="all" style="border: 1px solid;text-align:center;background-color: #FFFFFF;border-collapse: collapse; border-color: #A6AAB6"><thead><tr style=" background-color: #E0E0F0;color: #161120"><th width="10px">Cell</th><th style="text-align:left;padding-left:5px;">Formula</th></tr></thead><tbody><tr><th width="10px" style=" background-color: #E0E0F0;color: #161120">P3</th><td style="text-align:left">{=SUMPRODUCT(<font color="Blue">C3:C7,--(<font color="Red">A3:A7<=E6</font>),--(<font color="Red">B3:B7>=D6</font>),IF(<font color="Red">B3:B7<E6,B3:B7,E6</font>)-IF(<font color="Red">A3:A7>D6,A3:A7,D6</font>)+1</font>)}</td></tr><tr><th width="10px" style=" background-color: #E0E0F0;color: #161120">Q3</th><td style="text-align:left">{=SUMPRODUCT(<font color="Blue">(<font color="Red">C3:C7</font>)*(<font color="Red">A3:A7<=E6</font>)*(<font color="Red">B3:B7>=D6</font>)*(<font color="Red">IF(<font color="Green">B3:B7<E6,B3:B7,E6</font>)-IF(<font color="Green">A3:A7>D6,A3:A7,D6</font>)+1</font>)</font>)}</td></tr></tbody></table><b>Entered with Ctrl+Shift+Enter.</b> If entered correctly, Excel will surround with curly braces {}.
<b>Note: Do not try and enter the {} manually yourself</b></td></tr></table><br />
Markmzz
 
Last edited:
Upvote 0
I did try entering as an array formula before, but it didn't work. I think I was including the entire column, so maybe that was the problem. If I enter as a single cell array formula then copy that cell to the rest of the range, it seems my problem is solved. Thanks!

I guess I am missing something in my understanding of when an array formula is required, and how they actually work in some of these situations. Is there a reference that I can check out to learn more? I would really like to understand why my first attempt doesn't work correctly.

Also, what is the trick to including the nice (and correctly displayed) Excel clips? I was really struggling to figure out why I couldn't get mine to display in the forum.

Thanks again!
 
Upvote 0
One more question...

I see that I can also use a SUM formula instead of the second SUMPRODUCT array furnction you suggested. Is there an advantage of one over the other?

I had thought that SUM array formulas had to be entered in the entire range at once, and that SUMPRODUCT would do the job without an array formula entry.
 
Upvote 0
One more question...

I see that I can also use a SUM formula instead of the second SUMPRODUCT array furnction you suggested. Is there an advantage of one over the other?

I had thought that SUM array formulas had to be entered in the entire range at once, and that SUMPRODUCT would do the job without an array formula entry.

SUMPRODUCT in many cases doesn't require CSE.....but as soon as you have an IF function (referencing an array or range) then it does......

There isn't much advantage in using SUMPRODUCT here.....I'd use SUM

Some types of "array formulas" need to be entered in a whole range, those that return an array as the result....but typically with SUM or SUMPRODUCT you get a single value
 
Upvote 0
One more question...

I see that I can also use a SUM formula instead of the second SUMPRODUCT array furnction you suggested. Is there an advantage of one over the other?

I had thought that SUM array formulas had to be entered in the entire range at once, and that SUMPRODUCT would do the job without an array formula entry.

I think that the Barry's explanation is sufficient for your questions here.

And have a look at the links that I posted.

Markmzz
 
Upvote 0

Forum statistics

Threads
1,224,508
Messages
6,179,189
Members
452,893
Latest member
denay

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