Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Custom Column - Pass current row as a record to a function

I'm trying to create a query that has a step that processes a column that contains a table th adds a custom column that uses a custom function to transform the contents of the table calue of the column.

I'm using the custom function since the transformation code is quite complex.

My issue is how to 2 part:

  1. How to a structure the call from "each" to pass the current row as a record parameter to my custom function
  2. Specifiy the correct parameter signature in my custom function to receive the record version of thje row passed by the call from "each"

Ideas much appreciated

 

  • Hi , Anonymous 

    According to your descripition, you want to create a custonm function in Power Query Editor.

    And you want to pass   a "record" type parameter in your custom function, and you want to use your table row as this parameter when we call the custom function.

    Here are the steps you can refer to :
    (1)We can create a customn column with the "record" type parameter like this:

    = (re as record) as table=>let rec=Table.FromRecords({re}) in rec

     

    (2)We can call this api in another table each row.

    We can click "Custom Column" in "Add Column" pane and enter this:

    And we can modify the M code like this then we can put this row record to our custom function.

    = Table.AddColumn(#"Changed Type", "Custom", each Query1(_)     )

    We can also use this M code , this is the same :

    = Table.AddColumn(#"Changed Type", "Custom", (x)=> Query1(x)     )

     

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

     

     

     

     

1 Reply

  • Hi , Anonymous 

    According to your descripition, you want to create a custonm function in Power Query Editor.

    And you want to pass   a "record" type parameter in your custom function, and you want to use your table row as this parameter when we call the custom function.

    Here are the steps you can refer to :
    (1)We can create a customn column with the "record" type parameter like this:

    = (re as record) as table=>let rec=Table.FromRecords({re}) in rec

     

    (2)We can call this api in another table each row.

    We can click "Custom Column" in "Add Column" pane and enter this:

    And we can modify the M code like this then we can put this row record to our custom function.

    = Table.AddColumn(#"Changed Type", "Custom", each Query1(_)     )

    We can also use this M code , this is the same :

    = Table.AddColumn(#"Changed Type", "Custom", (x)=> Query1(x)     )

     

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly