Calculate Cumulative total as a part of Array

CA_Punit

Well-known Member
Joined
Nov 18, 2019
Messages
944
Office Version
  1. 365
Platform
  1. Windows
I am stuck with Cumulative total of an array which is a part of Bigger formula.

I have the following

Book11.xlsx
ABCDEF
1Total SalesCategory0a
21,99,000.001.0059,700.0059,700.00 Current Want this to be
33,00,000.001.0049,600.00-10,100.001,01,000.00101000
41,99,000.001.001,02,866.6753,266.673,00,000.004,01,000.00
51,99,000.001.001,42,666.6739,800.0037,50,000.0041,51,000.00
61,99,000.001.001,82,466.6739,800.00
71,99,000.001.002,22,266.6739,800.00
8
9
10SlabCategory 1Category 2
1110.30.4
12900010.20.3
131500010.20.2
149000010.20.2
Sheet1 (3)
Cell Formulas
RangeFormula
C2:C7C2=SUM($D$1:D2)
D2:D7D2=SUM(IFERROR(LET(a,(($A$12:$A$14-$A$11:$A$13)-IF(($A$12:$A$14-$A$11:$A$13)+IF((C1-($A$12:$A$14-1))>0,0,(C1-($A$12:$A$14-1)))<0,0,($A$12:$A$14-$A$11:$A$13)+IF((C1-($A$12:$A$14-1))>0,0,(C1-($A$12:$A$14-1)))))/CHOOSE(B2,$B$11:$B$13,$C$11:$C$13),b,IFERROR(MATCH(A2,a,1),0)+1,c,IFERROR(MATCH(A2,a,1),0),d,INDEX(a,SEQUENCE(b),1),e,IFERROR(INDEX(a,SEQUENCE(c),1),0),f,INDEX(CHOOSE(B2,$B$11:$B$13,$C$11:$C$13),SEQUENCE(b)),IF(A2>d,d,A2-SUM(e))*f),0))
E3:E5E3=(($A$12:$A$14-$A$11:$A$13)-IF(($A$12:$A$14-$A$11:$A$13)+IF((C2-($A$12:$A$14-1))>0,0,(C2-($A$12:$A$14-1)))<0,0,($A$12:$A$14-$A$11:$A$13)+IF((C2-($A$12:$A$14-1))>0,0,(C2-($A$12:$A$14-1)))))/CHOOSE(B3,$B$11:$B$13,$C$11:$C$13)
F4F4=E4+F3
F5F5=F4+E5
Dynamic array formulas.


Since it is an part of array, I want the cumulative total to be in array.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
How about a description of the task so that we don't have to spend hours trying to decipher your existing formulas?
 
Upvote 0
Book11.xlsx
ABCDEFGH
2Say for instance I have a array derieved from a formula and it looks like this
3Array (for Instance)
4700200
51000500
61100600
7
8now I want to get the cumulative total like
9700
101700
112800
12
13
14Since it is a part of an array formula I cannot refer the array from cells. It will be a part of array
15
Sheet3
Cell Formulas
RangeFormula
A4:A6A4=G4:G6+500
A9A9=A4
A10A10=A5+A9
A11A11=A10+A6
Dynamic array formulas.
 
Upvote 0
That part is obvious, I was referring to the task as a whole.

C2:C7 and D2:D7 appear to be intermediate helper arrays. Taking those away, what is the procedure to get from the values in A2:A7 to the final result?
 
Upvote 0
But that is not what i want now.
What you want and what is possible are not always the same thing.

The only way to create a running total in the way that you want to is by nesting subtotal and offset. This will only work with ranges, not with arrays.
 
Upvote 0
I'm not sure I understand what you want. For an array generated by a formula as simple as the one shown in A4:A6, maybe ...

Select A9:A11 and paste this array formula in the formula bar
=SUBTOTAL(9,OFFSET(G$4:G$6,,,ROW(G$4:G$6)-ROW(G$4)+1))+500*(ROW(G$4:G$6)-ROW(G$4)+1)
Control+Shift+Enter

M.
 
Upvote 0
The only way to create a running total in the way that you want to is by nesting subtotal and offset. This will only work with ranges, not with arrays.

There's another way involving TRANSPOSE and MMULT, but it's ugly. Maybe using LET it might be reasonable. But even so, I think CA_Punit might be going about this the wrong way. Rather than saying, "this is a sub-problem I want to solve", he could present the whole problem. Anything complicated enough to require an in-formula sub formula to have a running total really would be more of a novelty than a usable formula. I think a UDF would make more sense.

Book1
ABCDEFGH
1
2Say for instance I have a array derieved from a formula and it looks like this
3Array (for Instance)
4700200
51000500
61100600
7
8now I want to get the cumulative total like
9700700700
10170017001700
11280028002800
12
13
14Since it is a part of an array formula I cannot refer the array from cells. It will be a part of array
Sheet4
Cell Formulas
RangeFormula
A4:A6A4=G4:G6+500
A9:A11A9=TRANSPOSE(MMULT(SEQUENCE(,ROWS(A4:A6))^0,IF(ROW(A4:A6)<=(TRANSPOSE(ROW(A4:A6))),A4:A6,0)))
G9:G11G9=TRANSPOSE(MMULT(SEQUENCE(,ROWS(G4:G6+500))^0,IF(SEQUENCE(ROWS(G4:G6+500))<=SEQUENCE(,ROWS(G4:G6+500)),A4:A6,0)))
H9:H11H9=TRANSPOSE(MMULT(SEQUENCE(,ROWS(A4#))^0,IF(SEQUENCE(ROWS(A4#))<=SEQUENCE(,ROWS(A4#)),A4#,0)))
Dynamic array formulas.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,625
Messages
6,120,598
Members
448,973
Latest member
ksonnia

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