Help for Custom Lambda Function

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,922
Office Version
  1. 365
Platform
  1. Windows
Hi,
I'm trying to create a LAMBDA function as follows:

Inputs
column of numbers: "arr"
fixed array: "flags" = {6, 9, 50, 200}
fixed integer: "lag" = 2

Process
Create 4 columns of:
Rolling sum of 6 values offset by 2 of "arr" (1)
Rolling sum of 9 values offset by 2 of "arr" (2)
Moving average of 50 values of (1) (3)
Moving average of 200 values of (2) (4)

Output
Single column of values:
Excel Formula:
=SIGN(SUM([1:4])/4)

So far I have:
Excel Formula:
=LET(arr,$J2#,f,INDEX(flags,1),l,f+lag-1,m,SEQUENCE(ROWS(arr)),IF(m>l,SUM(OFFSET($J$2,m-l,,f)),0))

If my values are in J2:J510 and I enter the formula into L2, it correctly returns 0 in L2:L9 but REF#! in L10 onwards
L9 should be SUM(J2:J7)
L10: SUM(J3:J8)
L11: SUM(J4:J9)
etc

It should then be easy to expand to the second column, similar values but a flag of 9 not 6 by looping over INDEX(flags,x)
I intuit for columns 3 and 4, something like If(Index(flags,x))<3,"SUM","AVERAGE" and adapt the SUM function to AVERAGE the moving range instead.

Can anyone help with this first part?

TIA, Jack
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,215,124
Messages
6,123,184
Members
449,090
Latest member
bes000

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