Forum Discussion
MichielS340
Sep 08, 2024Brass Contributor
Loop through table column with spill formula
Hi, I get a nested array calculation error if I try to loop through the rows and for each row prepare a list of working days. See attached file. Anyone a suggestion how I can work my way around ...
- Sep 08, 2024
You're receiving the #CALC! error because BYROW is designed to return a scalar for each row - 7 rows, 7 scalars.
One approach is to use thunks. For example,
=LET( i, SEQUENCE(ROWS(Table2)), thunk, LAMBDA(x, LAMBDA(x)), thunks, BYROW( Table2[Begin], LAMBDA(x, LET( StartDag, x, EindDag, OFFSET(x, , 1), AantalUur, OFFSET(x, , 2), NettoWerkdagen, NETWORKDAYS(StartDag, EindDag), LijstWerkdagen, WORKDAY(StartDag - 1, SEQUENCE(NettoWerkdagen)), UurPerDag, AantalUur / NettoWerkdagen, thunk( HSTACK( LijstWerkdagen, EXPAND(UurPerDag, NettoWerkdagen, , UurPerDag) ) ) ) ) ), DROP(REDUCE("", i, LAMBDA(acc, v, VSTACK(acc, INDEX(thunks, v, 1)()))), 1) )
There are several discussions in this forum that cover thunks thoroughly. This site is a good primer for getting started:
What is a thunk in an Excel lambda function? - FLEX YOUR DATA
MichielS340
Sep 09, 2024Brass Contributor
Many thanks, I need some time to digest, but it works quite elegant!
Lorenzo
Sep 09, 2024Silver Contributor
You're MichielS340
All credits due Patrick2788. https://support.microsoft.com/en-us/office/map-function-48006093-f97c-47c1-bfcc-749263bb1f01 avoids OFFSETing (cf. your initial formula), passing your 3 required arrays ([Begin], [Eind], [Hours]) to the function