Forum Discussion
Syntax for calling Lambda via INDIRECT
Since I am not sure I fully understand the use case for INDIRECT, here are some techniques that might be of relevance. I started with a validation list of function names as text. That allows me to use validation to select the desired function names. I then built an array of functions in memory
FunctionList = VSTACK(SINλ, COSλ, TANλ)
where
SINλ = LAMBDA(ϑ, SIN(RADIANS(ϑ)));
COSλ = LAMBDA(ϑ, COS(RADIANS(ϑ)));
TANλ = LAMBDA(ϑ, TAN(RADIANS(ϑ)));The worksheet formula could then be
= LET(
Fnλ, XLOOKUP(function, validationList, FunctionList),
MAP(Fnλ, ϑ, Applyλ)
)
where
Applyλ = LAMBDA(Fnλ₁, ϑ₁, Fnλ₁(ϑ₁))If you find having formulas on the worksheet distracting or ugly, you could wrap the whole shooting-match within a further Lambda to give
= Indirectλ(function, ϑ)- ecovonreinMay 02, 2023Iron Contributor
This is essentially the same approach that Sergei takes with SWITCH. It does not work when the target Lambdas are in a foreign Workbook.
I have wondered whether the challenge of poking numbers out of a time grid might be a suitable matter for Power Query. (I don't know this thing, really.) The grid is highly readable to a human so I would certainly expect the Copilot to be able to do it. Not that I would know where to start 🙂🙂...
- PeterBartholomew1May 02, 2023Silver Contributor
I am more used to using a scratch worksheet in the same book for testing/purposes so I have little experience of the scenario you outline. At least I now have some idea as to how the sheet local names arise for your Lambda functions. I tend to use workbook scoped Lambdas and keep the sheet localisation to the parameter names rather than the function, but I appreciate that may not be possible.
- ecovonreinMay 03, 2023Iron ContributorI do that too, Peter. I have a local scope Lambda "SUMV12" with a very short function signature whose only purpose it is to call "Private.SUMV12" in the global scope, supplying all sorts of local context to the global Lambda with the long signature. The latter is centrally maintained and reloaded each time the sheet is opened, so that we can maintain the core Lambda functions and push out to all spreadsheets.