Forum Discussion
M Language - Custom Functions -> Passing a Table by a string name
- Anonymous6 years ago
Here is the solution...
let
TargetTable = (TargetTableName as text) as table=>
let
TargetTable = Record.Field(#sections[Section1], TargetTableName)
in
TargetTable,
MyTable = TargetTable("ccontl")
in
MyTable
Here is the solution...
let
TargetTable = (TargetTableName as text) as table=>
let
TargetTable = Record.Field(#sections[Section1], TargetTableName)
in
TargetTable,
MyTable = TargetTable("ccontl")
in
MyTable
Hi Anonymous and ImkeF This approach is very cool. I have been struggling with finding a way to integrate strings into expression values. Anonymous Your soloution is great! Do you think there is a way to further refine it and remove the need to cosider it a table and simply a variable or are we trapped by type?
- ImkeF6 years agoCommunity Champion
Hi Anonymous ,
the definition of the output type is optional, so if you remove it, you can use this query to reference queries of any type.
let fnTargetQuery = (TargetQueryName as text) => Record.Field(#sections[Section1], TargetQueryName), CallFunction = fnTargetQuery("ccontl") in CallFunction... code is slighty rewritten ...
- Anonymous6 years agoNot applicable
ImkeF Thanks alot this is a really powerfull pattern.