Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hi all,
I have this table TableOfTable:
NameOfTable | Param1 | Param2 |
t1 | p1 | p2 |
t2 | p3 | p4 |
I have a function written in Power Query M, myFunction, which is working correctly: the input parameters for the function are:
I want to write another function in power query who call myFunction for each record of the table above, passing the right parameter. So i wrote this code:
let
i = 0,
rec = HierarchiesTable{i},
myTable= Record.Field(rec, "NameOfTable"),
parameter1 = Record.Field(rec, "Param1"),
parameter2= Record.Field(rec, "Param2"),
Output = myFunction(myTable, parameter1 , parameter2)
in Output
What is the problem? When i call myFunction passing the first parameter, i'm passing a string with the name of the table, not the table on which i want to apply the function! How can i resolve this? How can i cycle over the record of TableOfTable?
Thank you
Solved! Go to Solution.
#Edited
As first guess, I'd give it a try with this
List.Transform(Table.toRecords(tableofTable), each MyFunction(Expressiona.Evaluate([NameOfTable],#shared), [Param1],[Param2]))
If you would be more specific, could get more specific answer (peraphs)
PS
After reading better the post, I suggest to give a look at this
using a table anme as parameter
let
conc=(utab,ntab)=>
let
lstabs=List.Transform({1..ntab}, each "w"&Text.From(Number.From(Text.End(utab,2))-ntab+_-1)),
Cws=Table.TransformRows(Expression.Evaluate(utab,#shared), (ru)=>Record.Combine(List.Transform(lstabs, each Expression.Evaluate(_,#shared){[Job=ru[Job]]})&{ru}))
in
Table.FromRecords(Cws)
in
conc
Hello @Anonymous
you have to call your function. So wy not add a new column and passing the three parameters.
=Table.AddColumn(PreviousStep, "New Column", each YourFuntion([NameOfTable],[Param1],[Param2])
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
I think you can do this using Expression.Evaluate. See if this works for your Output line:
Output = myFunction(Expression.Evaluate(myTable, #shared), parameter1, parameter2)
For understanding what's happening, I'd recommend reading this:
#Edited
As first guess, I'd give it a try with this
List.Transform(Table.toRecords(tableofTable), each MyFunction(Expressiona.Evaluate([NameOfTable],#shared), [Param1],[Param2]))
If you would be more specific, could get more specific answer (peraphs)
PS
After reading better the post, I suggest to give a look at this
using a table anme as parameter
let
conc=(utab,ntab)=>
let
lstabs=List.Transform({1..ntab}, each "w"&Text.From(Number.From(Text.End(utab,2))-ntab+_-1)),
Cws=Table.TransformRows(Expression.Evaluate(utab,#shared), (ru)=>Record.Combine(List.Transform(lstabs, each Expression.Evaluate(_,#shared){[Job=ru[Job]]})&{ru}))
in
Table.FromRecords(Cws)
in
conc