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
PeterBartholomew1
Sep 08, 2024Silver Contributor
The problem arises on the line
LET(
...
LijstWerkdagen, WORKDAY(StartDag - 1, SEQUENCE(NettoWerkdagen)),
where SEQUENCE( ) generates an array of days which BYROW( ) then attempts to assemble into an array of arrays. While I was working through the formula, I downloaded a Lambda (helper) function 'MAPĪ»' that I only finished writing last week (maybe some checking required).
That would at least allow you to look at numbers rather than error messages.
- MichielS340Sep 09, 2024Brass ContributorThanks for your input!