Forum Discussion
Passing a Table as a variable (in a LAMBDA() function)
- Nov 25, 2022
ColinJHarrison I think the point you are missing is that Table1 may refer to the table itself as a dynamic array and to the name of the table which is no more than a text. The LAMBDA needs to refer to the table name.
Remove the quotes in A2 and change the formula to this:
=LAMBDA(Tn,INDIRECT(Tn&"[#Headers]"))(A2)
Similar for the named LAMBDA function. You want to feed it the text that is in A2, so
=TPX(A2) will work.
See attached.
ColinJHarrison I think the point you are missing is that Table1 may refer to the table itself as a dynamic array and to the name of the table which is no more than a text. The LAMBDA needs to refer to the table name.
Remove the quotes in A2 and change the formula to this:
=LAMBDA(Tn,INDIRECT(Tn&"[#Headers]"))(A2)
Similar for the named LAMBDA function. You want to feed it the text that is in A2, so
=TPX(A2) will work.
See attached.
- chippedlensNov 11, 2023Copper Contributor
I'm trying to do the same thing, pass a table to a lambda function. But I would greatly prefer a solution without the use of INDIRECT as it slows calculations way down as it is volatile. (Calculates every time anything changes.)
Anyone have a solution for passing a table to a lambda function that does not use INDIRECT?
- chippedlensNov 11, 2023Copper ContributorOk, figured it out, use INDEX instead of INDIRECT. Here is an example that returns the data from a column in a table:
=LAMBDA(TableAll,ColumnTitle,DROP(INDEX(TableAll,0,MATCH(ColumnTitle,INDEX(TableAll,1,0),0)),1,))(Table1[#All],"Cost")
Found a useful discussion:
https://superuser.com/questions/1713772/dynamic-table-name-in-excel-lambda-function-with-structured-references-without-i