New formula for cumulative values

Dave Patton

Well-known Member
Joined
Feb 15, 2002
Messages
6,486
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
The examples shows a recap of bank account values. The results are correct but the cumulative value formulas are copied down.
The number of banks may increase and the number of months will increase.
Can I replace the formulas that provides the cumulative values with one formula?

Bk_InfoV1.xlsx
ABCDEFGHIJ
1OutstandingPer
2Bank NamePer recordsAmountsBankDifference
3a12,000.000.0012,000.000.00
4b16,538.23-4,650.0011,888.230.00
5c154.360.00154.360.00
6m-1,330.290.00-1,330.290.00
7v-4,704.00744.00-3,960.000.00
8Total22,658.30-3,906.0018,752.300.00
9 J
10
11
12
13 202312202401202402202403202404202405202406202407Total
14a10,000.002,000.0012,000.00
15b10,398.50-500.00-15.43405.162,200.00-600.004,650.0016,538.23
16c371.56-108.60-108.60154.36
17m-1,299.99-30.30-1,330.29
18v-3,960.00-425.00-105.00-214.00-4,704.00
19Total16,810.06-1,799.991,845.67296.561,775.00-600.004,545.00-214.0022,658.30
20Bank by month# of Months8
21
22
23Cumulative2023-122024-012024-022024-032024-042024-052024-062024-07
24a10,000.0010,000.0012,000.0012,000.0012,000.0012,000.0012,000.0012,000.00
25b10,398.509,898.509,883.0710,288.2312,488.2311,888.2316,538.2316,538.23
26c371.56371.56262.96154.36154.36154.36154.36154.36
27m0.00-1,299.99-1,330.29-1,330.29-1,330.29-1,330.29-1,330.29-1,330.29
28v-3,960.00-3,960.00-3,960.00-3,960.00-4,385.00-4,385.00-4,490.00-4,704.00
29Total16,810.0615,010.0716,855.7417,152.3018,927.3018,327.3022,872.3022,658.30 
30
BK_Rec and recap
Cell Formulas
RangeFormula
A3:B8A3=GROUPBY(T_[BK],T_[Amount],SUM)
C3:C7C3=-SUM((T_[BK]=A3)*T_[Amount]*(T_[Cleared]=""))
C8:E8C8=SUM(C3:C7)
E3:E7E3=B3+C3-D3
E9E9=IF(E8=0, "J","L")
A13:J19A13=PIVOTBY(T_[BK],TEXT(T_[Date],"yyyymm"),T_[Amount],SUM)
D20D20=COUNTA($B$13:$Z$13)-1
A24:A29A24=A14:A19
B23:I23B23=LET(m,COUNTA(B13:AA13)-1,EOMONTH(DATE(2023,12,0),SEQUENCE(,m)))
B24:I28B24=TAKE(SCAN(0,B14:Z14,SUM),,$D$20)
B29:J29B29=LET(a,SUM(B24:B28),IF(a,a,""))
Dynamic array formulas.
Cells with Conditional Formatting
CellConditionCell FormatStop If True
E9Expression=E9="L"textNO
E9Expression="G7=""J"""textNO
H7Expression=H7="L"textNO
H7Expression="G7=""J"""textNO
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
The formula in B24 calculates the accumulated total for that row and the formula is copied down.
Range A24:A28 is just a copy of A14:A18.
The formulas yield the correct values.

Is it possible to replace the formulas in A23:I29 with a more sophisticated (newer) formula or formulas?
 
Upvote 0
In B23,
Excel Formula:
=LET(hr,B13:I13,a,B14:I18,za,BYCOL(hr,LAMBDA(cha,LEFT(cha,4)&"-"&RIGHT(cha,2))),zb,MAKEARRAY(ROWS(a),COLUMNS(a),LAMBDA(r,c,SUM(INDEX(a,r,1):INDEX(a,r,c)))),zc,MAKEARRAY(1,COLUMNS(zb),LAMBDA(ro,clm,SUM(INDEX(zb,,clm)))),VSTACK(za,zb,zc))
 
Upvote 0
Something like this perhaps:
Book1
ABCDEFGHI
13
14a10000200012000
15b10398.5-500-15.43405.162200-6004650
16c371.56-108.6-108.6
17m-1299.99-30.3
18v-3960-425-105-214
19
20
21
22
23
24a1000010000120001200012000120001200024000
25b10398.59898.59883.0710288.2312488.2311888.2316538.2316538.23
26c371.56371.56262.96154.36154.36154.36154.36154.36
27m0-1299.99-1330.29-1330.29-1330.29-1330.29-1330.29-1330.29
28v-3960-3960-3960-3960-4385-4385-4490-4704
Sheet3
Cell Formulas
RangeFormula
B24:I28B24=MAKEARRAY(5,8,LAMBDA(r,c,SUM(INDEX(B14:I18,r,1):INDEX(B14:I18,r,c))))
Dynamic array formulas.
 
Upvote 0
Thanks very much kvsrinivasamurthy and Cubist; both suggestions are excellent.

They both work but I will have review each one carefully. I wish I could mark them both as solutions.
 
Upvote 0
Just for fun, a few more options could be:

Excel Formula:
=LET(
    vals, IFERROR(--DROP(DROP(A13#,1,1),-1,-1),0),
    DROP(SCAN(0,EXPAND(vals,,COLUMNS(vals)+1),LAMBDA(a,v,IFERROR(a+v,0))),,-1)
)

Or:

Excel Formula:
=LET(
    vals, IFERROR(--DROP(DROP(A13#,1,1),-1,-1),0),
    n, SEQUENCE(COLUMNS(vals)),
    MMULT(vals,--(n<=TOROW(n)))
)

Or direct from the source table (with header and total row):

Excel Formula:
=LET(
    eom, EOMONTH(+T_[Date],0),
    unq, TOROW(UNIQUE(SORT(eom))),
    VSTACK(
        HSTACK("Cumulative",TEXT(unq,"yyyy-mm")),
        GROUPBY(T_[BK],(eom<=unq)*T_[Amount],SUM,0,1)
    )
)
 
Upvote 0
Solution

Forum statistics

Threads
1,224,813
Messages
6,181,117
Members
453,021
Latest member
Justyna P

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