Forum Discussion
necmik
3 years agoMicrosoft Employee
Text to Function definition
Is there a way to transform a text to function definition in M language? What I need is something like Function.From(text). For instance this text contains a function definition with empty body: Tex...
- 3 years ago
I was hoping for something I could paste into the Advanced Editor but I'll take a guess at what I think you mean.
Is this close to what you're after?
let Source = #table({"ListCol"},{{{[name="InputColumn1", type="text"],[name="InputColumn2", type="number"]}},{{[name="InputColumn1", type="text"]}}}), #"Added Custom" = Table.AddColumn(Source, "ToText", each "(" & Text.Combine(List.Transform([ListCol], each [name] & " as " & [type]), ", ") & ") as any => ""..."""), #"Added Custom1" = Table.AddColumn(#"Added Custom", "ToFunction", each Expression.Evaluate([ToText])) in #"Added Custom1"
necmik
3 years agoMicrosoft Employee
Actually I had given in my previous answer. My input is:
{
[name="InputColumn1", type="text"],
[name="InputColumn2", type="number"]
}
What I want as output is:
(InputColumn1 as text, InputColumn2 as number) as any => ...
(A function type)
AlexisOlson
3 years agoSuper User
I was hoping for something I could paste into the Advanced Editor but I'll take a guess at what I think you mean.
Is this close to what you're after?
let
Source = #table({"ListCol"},{{{[name="InputColumn1", type="text"],[name="InputColumn2", type="number"]}},{{[name="InputColumn1", type="text"]}}}),
#"Added Custom" = Table.AddColumn(Source, "ToText", each "(" & Text.Combine(List.Transform([ListCol], each [name] & " as " & [type]), ", ") & ") as any => ""..."""),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "ToFunction", each Expression.Evaluate([ToText]))
in
#"Added Custom1"
- necmik3 years agoMicrosoft Employee
That is what I exactly want. I didn't expect Expression.Evaluate would be enough because of the word "Evaluate". Very thanks