Forum Discussion

DanFromMontreal's avatar
2 years ago
Solved

Passing table field name as a parameter to a function in PowerM

Hello all, I'm struggling to pass a table field name as a parameter to a function.

I've tried several things but none worked.... this 

DesiredField is the column in the table "tblFolder" I want to return a value from.

I'm sure it is simple but since I'm a novice....

 

//fxFieldContent
(Year as number, DesiredField as text) =>
let
  aaa = DesiredField,
  Source = tblFolder,
  #"Filtered lines" = Table.SelectRows(Source, each ([Year] = Year) and ([Selection] = "X")),

  //FieldContent = #"Filtered lines"{0}[Path]& #"Filtered lines"{0}[File] // Working but field in hardcoded
  //FieldContent = #"Filtered lines"{0}{DesiredField} doesn't work
  //FieldContent = #"Filtered lines"{0}[aaa] //doesn't work
  //FieldContent = #"Filtered lines"{0}[#"Record.Field(_,DesiredField)"] //doesn't work

  // By using [DesiredField], it is trying to find the field "DesiredField" in tblFolder, which does not exist!

  //How can I change the [DesiredField] and use the parameter "DesiredField" to select my   desired field?

 FieldContent = #"Filtered lines"{0}[DesiredField]
in
FieldContent

 

Thank you for your help.

  • Hi DanFromMontreal  you were close 😉

     

     

    Record.Field(#"Filtered lines"{0}, aaa)
    
    or
    
    Record.Field(#"Filtered lines"{0}, DesiredField)
    

     

3 Replies