Forum Discussion
Text to Function definition
- 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"
The BIccountant has a great blog post on this with a custom fn for you to use.
Yep. It looks like Expression.Evaluate is key here.
- necmik3 years agoMicrosoft Employee
How can I use Expression.Evaluate here? I read the BIccountant blog. It gave me some idea but I couldn't figure out how to create a function from text. To be clear what I am trying to do is:
I have a table and this table has a column contains input schema as list of records:
{
[name="InputColumn1", type="text"],
[name="InputColumn2", type="number"]
}
My aim is to generate a function like this:
(InputColumn1 as text, InputColumn2 as number) as any => ...
- AlexisOlson3 years agoSuper User
Can you give an explicit example of input and expected output? I can't quite figure out exactly what part you're stuck on.
- necmik3 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)