Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Call a function on a table, having only the name of the table

Hi all,

I have this table TableOfTable:

NameOfTableParam1Param2
t1p1p2
t2p3p4

 

I have a function written in Power Query M, myFunction, which is working correctly: the input parameters for the function are:

  1. myTable type table
  2. parameter1 type string
  3. parameter2 type string

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

1 ACCEPTED SOLUTION
Anonymous
Not applicable

#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

 

 

View solution in original post

3 REPLIES 3
Jimmy801
Community Champion
Community Champion

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

AlexisOlson
Super User
Super User

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:

https://ssbi-blog.de/blog/technical-topics-english/the-environment-concept-in-m-for-power-query-and-...

Anonymous
Not applicable

#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

 

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors