ACCUMULATE

ACCUMULATE(init_value,funcs,[iterations])
init_value
beginning value for calculations
funcs
a LAMBDA function, or array of LAMBDA functions
iterations
number of iterations to perform funcs, optional

Applies a set of functions consecutively to a seed value a prescribed number of times.

tboulden

Board Regular
Joined
Jan 14, 2021
Messages
73
Office Version
  1. 365
Platform
  1. Windows
Given an initial value and a unary LAMBDA function (or array of unary LAMBDA functions), apply each function sequentially to initial value; if iterations argument is provided, repeats the applications for that many iterations. Output is a table whose dimensions are [ROWS(funcs)*iterations]x[COLUMNS(funcs)].

Easiest way to provide an array of LAMBDAs is to use CHOOSE: CHOOSE({1,2,3},LAMBDA(x,...),LAMBDA(y,...),LAMBDA(z,...)). LAMBDAs in example are straight-forward, i.e. ADDTWO := LAMBDA(x,x+2), TIMESTHREE := LAMBDA(x,x*3)

Created to generalize sub-steps from AMORTIZE.

Excel Formula:
=LAMBDA(init_value,funcs,[iterations],
    LET(
        fxns,IF(TYPE(funcs)=64,funcs,CHOOSE({1},funcs)),
        iter,IF(ISOMITTED(iterations),1,iterations),
        fxns_array,
            MAKEARRAY(iter*ROWS(fxns),COLUMNS(fxns),
                LAMBDA(i,j,INDEX(fxns,MOD(i-1,ROWS(fxns))+1,j))
            ),
        SCAN(init_value,fxns_array,LAMBDA(acc,fn,fn(acc)))
    )
)

LAMBDA_COMPOSE.xlsx
ABCDEFGHIJKLMNOP
1
22139139Balance100,000100,000.00100,416.6791,855.92
3310714Rate5%91,855.9292,238.6583,677.90
44139141648Periods1283,677.9084,026.5675,465.81
559113349469275,465.8175,780.2567,219.51
663335105929428267,219.5167,499.5958,938.84
710510732128328056058,938.8459,184.4250,623.67
83213239695605621,68650,623.6750,834.6042,273.85
91,6871,6843,36842,273.8542,449.9933,889.25
103,3683,37010,11033,889.2534,030.4525,469.70
1110,11110,10820,21625,469.7025,575.8317,015.08
1217,015.0817,085.978,525.23
138,525.238,560.750.00
SCAN
Cell Formulas
RangeFormula
A2:A6A2=ACCUMULATE(1,LAMBDA(x,x+1),5)
C2:E2C2=ACCUMULATE(1,CHOOSE({1,2,3},LAMBDA(x,x),ADDTWO,TIMESTHREE))
G2:I11G2=ACCUMULATE(1,CHOOSE({1,2,3;4,5,6},LAMBDA(x,x),ADDTWO,TIMESTHREE,ADDONE,MINUSTHREE,TIMESTWO),5)
N2:P13N2=ACCUMULATE(balance*1,CHOOSE({1,2,3},LAMBDA(x,x),LAMBDA(x,x*(1+rate/12)),LAMBDA(x,x-PMT(rate/12,periods,-balance))),periods)
C4:E8C4=ACCUMULATE(1,CHOOSE({1,2,3},LAMBDA(x,x),ADDTWO,TIMESTHREE),5)
Dynamic array formulas.
Named Ranges
NameRefers ToCells
balance=SCAN!$L$2N2
periods=SCAN!$L$4N2
rate=SCAN!$L$3N2
 
Upvote 0

Forum statistics

Threads
1,224,836
Messages
6,181,251
Members
453,027
Latest member
Lost_in_spreadsheets

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