Can an array formula reliably do this kind of totaling?

dcoons

Board Regular
Joined
Apr 21, 2002
Messages
56
I want to sum (by month) sales by person and multiply by the price to get total sales by month.

I thought something like {=SUM(SUM(B5:E12)*G5:G12)} or just plain {=SUM(B5:E12)*G5:G12} would work, but it doesn't, as you can see in the cell identified as "Wrong". The cell marked "Right" is a simple sum of the extended products above it--I added the sales in weeks 1 thru 4 then multiplied the total by the price for each row. Is there an array formula or some other approach that won't involve extra/hidden rows to accomplish the task? It needs to span blank rows and text without blowing up. In a test, I essentially created the Red Team block and was able to get the correct answer. However, it may have been dumb luck--once I edited or added to it so that it was more realistic like what I've shown here it quit working. I'm trying to avoid a normal formula like =sum(B5:E5)*G5+sum(B6:E6)* G6+.... as there are quite a few rows an this becomes immediately tedious. Of course, if you have some other slick way of doing this, I'd be happy to see that too!


Excel 2010
ABCDEFGHI
1Sales
2JanPrice
3wk1wk2wk3wk4JanExt Jan
4Red Team
5Joe1111520
6Mary2929244
7Fred5544590
8
9Blue Team0
10Jane1233654
11Marge5633351
12Kevin89335115
13
142418<< WrongRight>>374
Sheet1
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Try the SumProduct with its native syntax:

=SUMPRODUCT(B5:E11,G5:G11)

as it's devised exactly for this, that is, for multiplying a set of numerical terms.
 
Upvote 0
Excellent--didn't realize excel do the 'right' thing when multiplying inside sumproduct--I thought the ranges had to be the same size. BTW, =SUMPRODUCT(B5:E11*G5:G11) works, the 'native syntax' =SUMPRODUCT(B5:E11,G5:G11) does not--it generates an error. But it doesn't need to be CSE.
 
Upvote 0
Excellent--didn't realize excel do the 'right' thing when multiplying inside sumproduct--I thought the ranges had to be the same size. BTW, =SUMPRODUCT(B5:E11*G5:G11) works, the 'native syntax' =SUMPRODUCT(B5:E11,G5:G11) does not--it generates an error. But it doesn't need to be CSE.

=SUMPRODUCT(B5:E11,G5:G11)

does work, provided that B5:E11 and G5:G11 consist of true numbers. If you are on a non-American system, try:

=SUMPRODUCT(B5:E11;G5:G11)
 
Upvote 0
Aladin, that will give you a #VALUE! error as the ranges are not the same size.

<b>Sheet1</b><br /><br /><table border="1" cellspacing="0" cellpadding="0" style="font-family:Calibri,Arial; font-size:11pt; background-color:#ffffff; padding-left:2pt; padding-right:2pt; "> <colgroup><col style="font-weight:bold; width:30px; " /><col style="width:64px;" /><col style="width:64px;" /><col style="width:64px;" /><col style="width:64px;" /><col style="width:64px;" /><col style="width:64px;" /><col style="width:64px;" /><col style="width:64px;" /></colgroup><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td > </td><td >B</td><td >C</td><td >D</td><td >E</td><td >F</td><td >G</td><td >H</td><td >I</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >5</td><td style="text-align:right; ">20</td><td style="text-align:right; ">30</td><td style="text-align:right; ">40</td><td style="text-align:right; ">50</td><td > </td><td style="text-align:right; ">1</td><td > </td><td >#VALUE!</td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >6</td><td style="text-align:right; ">24</td><td style="text-align:right; ">36</td><td style="text-align:right; ">48</td><td style="text-align:right; ">60</td><td > </td><td style="text-align:right; ">2</td><td > </td><td > </td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7</td><td style="text-align:right; ">28</td><td style="text-align:right; ">42</td><td style="text-align:right; ">56</td><td style="text-align:right; ">70</td><td > </td><td style="text-align:right; ">3</td><td > </td><td > </td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >8</td><td style="text-align:right; ">32</td><td style="text-align:right; ">48</td><td style="text-align:right; ">64</td><td style="text-align:right; ">80</td><td > </td><td style="text-align:right; ">4</td><td > </td><td > </td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >9</td><td style="text-align:right; ">36</td><td style="text-align:right; ">54</td><td style="text-align:right; ">72</td><td style="text-align:right; ">90</td><td > </td><td style="text-align:right; ">5</td><td > </td><td > </td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >10</td><td style="text-align:right; ">40</td><td style="text-align:right; ">60</td><td style="text-align:right; ">80</td><td style="text-align:right; ">100</td><td > </td><td style="text-align:right; ">6</td><td > </td><td > </td></tr><tr style="height:18px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >11</td><td style="text-align:right; ">44</td><td style="text-align:right; ">66</td><td style="text-align:right; ">88</td><td style="text-align:right; ">110</td><td > </td><td style="text-align:right; ">7</td><td > </td><td > </td></tr></table><br /><table style="font-family:Arial; font-size:10pt; border-style: groove ;border-color:#00ff00;background-color:#fffcf9; color:#000000; "><tr><td ><b>Spreadsheet Formulas</b></td></tr><tr><td ><table border = "1" cellspacing="0" cellpadding="2" style="font-family:Arial; font-size:9pt;"><tr style="background-color:#cacaca; font-size:10pt;"><td >Cell</td><td >Formula</td></tr><tr><td >I5</td><td >=SUMPRODUCT(B5:E11,G5:G11)</td></tr></table></td></tr></table> <br /><br /><span style="font-family:Arial; font-size:9pt; font-weight:bold;background-color:#ffffff; color:#000000; ">Excel tables to the web >> </span>
 
Upvote 0
Aladin, that will give you a #VALUE! error as the ranges are not the same size.
...

My bad. I kept reading B5:B11 while writing down B5:E11. My concern clearly does not apply. One of Sum or SumProduct with the * operator is the choice. If the ranges involved do house formula blanks or other text:

=SUM(IF(ISNUMBER(1/(B1:E11*G1:G11)),B1:E11*G1:G11))

confirmed with control+shift+enter, not just enter, would be the way out. The foregoing would behave like the native SumProduct with appropriate ranges.
 
Upvote 0
OK, one more twist. If someone typed a bit of text in C8 of the original example, the =sumproduct(rng*rng) will fail due to the text value on that row. Any way to have sumproduct ignore text in this context? or treat it as a zero?
 
Upvote 0

Forum statistics

Threads
1,213,496
Messages
6,113,993
Members
448,539
Latest member
alex78

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