Forum Discussion
Iterative Lambda with indirect
- Apr 27, 2023
Power Query option attached
Note that the 1st Refresh within an Excel session takes more time (time for the .Net Framework to load) that the next Refresh(es)
The main challenge is that of combining your tables into one (it could be by replicating the Tables using PQ or building the table in memory using Lambda functions). To combine the tables, I have converted them to an array of Thunks, which I then expand using REDUCE. It was not obvious to me whether your tables have to same headers as one another or, even better, could be regarded as a 3D range.
For the conversion, I defined a Lambda function Thunkλ defined by
Thunkλ
= LAMBDA(x, LAMBDA(x))
I then defined named Thunks to hold the tables and stacked them to form a named array.
Tab_CLPC_415ϑ
= Thunkλ(EXPAND(Tab_CLPC_415, , 4, "4.1.5"))
Tab_CLPC_413ϑ
= Thunkλ(EXPAND(Tab_CLPC_413, , 4, "4.1.3"))
Note: I added a column to hold the Table value. A stacked table could then be returned using
Tab_Arrayϑ
= VSTACK(Tab_CLPC_415ϑ, Tab_CLPC_413ϑ)
= REDUCE(HSTACK(headers,"Value"), Tab_Arrayϑ,
LAMBDA(stack,Tabϑ,
VSTACK(stack, Tabϑ())
)
)
but I chose to continue with the "ProdA" lookups, so used
= LET(
Tab_Stacked, REDUCE(HSTACK(headers,"Value"), Tab_Arrayϑ,
LAMBDA(stack,Tabϑ,
VSTACK(stack, Tabϑ())
)
),
Tab_Body, DROP(Tab_Stacked, 1),
Country_Stacked, CHOOSECOLS(Tab_Body, 1),
ProdA_Stacked, CHOOSECOLS(Tab_Body, 2),
Value_Stacked, CHOOSECOLS(Tab_Body, 4),
XLOOKUP(Country, IF(ProdA_Stacked=2, Country_Stacked), Value_Stacked)
)
By now, you are probably wishing you hadn't asked the question and I cannot be sure I have answered it since there is guesswork involved in setting up the problem!