Array of SUMs?

BrianGGG

Board Regular
Joined
Mar 5, 2016
Messages
62
Hello.

I have a simple set of numbers as below:


BCD

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]73[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]6[/TD]

[TD="align: center"]74[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]9[/TD]

[TD="align: center"]75[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]12[/TD]

[TD="align: center"]76[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]3[/TD]

</tbody>
Summary





I'd like to return an array of column sums rather than the grand total sum of all numbers, e.g. my desired answer is {24;26;30} rather than 80.
However, any syntax that I give to sum (e.g. SUM(b73:d76), etc.) gets mashed up into a single total.

My goal is to write a single formula to "spill" across the columns with the new dynamic arrays (rather than copy the formula across). Any array function (with or without the new dynamic array functions like SEQUENCE) will work for me.

Any ideas?


thanks
BrianGGG
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Array-enter (press ctrl+shift+Enter instead of just Enter) a formula that contains the following:

SUM(INDEX(B73:D76,0,{1,2,3}))

or more generally:

SUM(INDEX(B73:D76,0,COLUMN(B73:D73)-COLUMN(A73)))

But that produces a horizontal array of 3 columns, the equivalent of {24,26,30}.

The syntax {24;26;30} is a veritcal array of 3 rows. Do you require the vertical array?
 
Last edited:
Upvote 0
Array-enter (press ctrl+shift+Enter instead of just Enter) a formula that contains the following:

SUM(INDEX(B73:D76,0,{1,2,3}))

or more generally:

SUM(INDEX(B73:D76,0,COLUMN(B73:D73)-COLUMN(A73)))

Have you tested these?

Both resolve to simply:

=SUM(B73:B76)

and not to how you would wish.

You can use SUBTOTAL and OFFSET here, though I prefer the non-volatile

MMULT(TRANSPOSE(ROW(B73:D76)^0),B73:D76)

which, suitably coerced (i.e. within some external function and committed with CSE), will produce:

{24,26,30}

which can be transposed if desired.

Regards
 
Upvote 0
Array-enter (press ctrl+shift+Enter instead of just Enter) a formula that contains the following:
SUM(INDEX(B73:D76,0,{1,2,3}))
or more generally:
SUM(INDEX(B73:D76,0,COLUMN(B73:D73)-COLUMN(A73)))
Have you tested these?

I did. In Excel 2010, I select 3 horizontal cells and array-enter either formula (press ctrl+shift+Enter instead of just Enter). The result is 24, 26 and 30 respectively.

BTW, we can get a vertical array by selecting 3 vertical cells and array-entering the following:

=SUM(INDEX(B73:D76,0,{1;2;3}))
or:
=SUM(INDEX(B73:D76,0,TRANSPOSE(COLUMN(B73:D73)-COLUMN(A73))))

I was surprised that =TRANSPOSE(SUM(INDEX(B73:D76,0,{1,2,3}))) does not work, array-entered of course.

PS.... Having said and demonstrated as much, I should say that nevertheless, there might be contexts where embedding the expression SUM(INDEX...) does not work, even when array-entered. We both know that there are expressions where Excel inexplicably does not treat the embedded expression as an array. XOR LX is expert at finding creative, albeit contorted, ways to fool Excel into delivering embedded arrays.
 
Last edited:
Upvote 0
Unfortunately, I am using the Insider Edition of Excel 2016 along with Dynamic Arrays.
There is no such thing as CSE anymore ...

And the following: SUM(INDEX(B73:D76,0,{1;2;3}))
does not work for me.

I have been trying to use some coercion myself, most notably the N(IF(1))) tricks...and none of them seem to return the right values.
I think SUM is a lost cause here, and I'm hoping/praying that a future version of dynamic arrays works more like TABLES and can be totaled and formatted, etc.


Thanks All...I'll keep trying


BrianGGG
 
Upvote 0
Here's what I get with the array formula:

BCD

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]73[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]6[/TD]

[TD="align: center"]74[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]9[/TD]

[TD="align: center"]75[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]12[/TD]

[TD="align: center"]76[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]3[/TD]

[TD="align: center"]77[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]78[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]79[/TD]
[TD="align: right"]24[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
Summary

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Array Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]B79[/TH]
[TD="align: left"]{=SUM(INDEX(B73:D76,0,{1;2;3}))}[/TD]
[/TR]
</tbody>[/TABLE]
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
I did. In Excel 2010, I select 3 horizontal cells and array-enter either formula (press ctrl+shift+Enter instead of just Enter). The result is 24, 26 and 30 respectively.

Apologies. I thought you were referring to a single-cell array formula (as I was in my solution), not to a multi-cell array formula.

XOR LX is expert at finding creative, albeit contorted, ways to fool Excel into delivering embedded arrays.

"Contorted"? "Fool Excel"? :)

Cheers
 
Upvote 0
Sorry if I messed this up.

I tried to select the 3 horizontal columns and enter the formula. If I try to delete one of the cells, it says that I can't change an array, so I think I succeeded. Yet:



BCD

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]73[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]6[/TD]

[TD="align: center"]74[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]9[/TD]

[TD="align: center"]75[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]12[/TD]

[TD="align: center"]76[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]3[/TD]

[TD="align: center"]77[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]78[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]79[/TD]
[TD="align: right"]24[/TD]
[TD="align: right"]24[/TD]
[TD="align: right"]24[/TD]

</tbody>
Summary

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Array Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]B79:D79[/TH]
[TD="align: left"]{=SUM(INDEX(B73:D76,0,{1;2;3}))}[/TD]
[/TR]
</tbody>[/TABLE]
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Sorry for the multiple replies...

Interestingly enough, the following DOES work:



BCD

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]73[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]6[/TD]

[TD="align: center"]74[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]9[/TD]

[TD="align: center"]75[/TD]
[TD="align: right"]10[/TD]
[TD="align: right"]11[/TD]
[TD="align: right"]12[/TD]

[TD="align: center"]76[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]3[/TD]

[TD="align: center"]77[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]78[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]79[/TD]
[TD="align: right"]24[/TD]
[TD="align: right"]26[/TD]
[TD="align: right"]30[/TD]

</tbody>
Summary

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Array Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=DAE7F5]#DAE7F5[/URL] "]B79:D79[/TH]
[TD="align: left"]{=SUM(INDEX(B73:D76,,SEQUENCE(1,3)))}[/TD]
[/TR]
</tbody>[/TABLE]
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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