Forum Discussion

Gugan_BI's avatar
Gugan_BI
Frequent Visitor
5 years ago
Solved

Multiple Add column

Hi,   Currently working on power bi solution which connects to dynamics 365. There are few optionset fields that need to be converted to actual values. I use the below query to get actual value of ...
  • Anonymous's avatar
    Anonymous
    5 years ago

    ok.

    Then you have to generate/construct the somethinkID list.

    You can create manually a list:

     

    lstID={productid,statusid,responseid} or select in somw way from column names list

     

    lstID= List.Select(Table.ColumnNames(tbl), each Text.EndsWith(_,"id"))

     

    Then you have to generate/construct in similar way a labelList.

     

    lstLabel={l1,l2,l3}

     

    Finally you could use list accumulate in the way I showed you.

     

    ASs I don't know the value.metadata function

    and MS explanation is very succint

     
     

     

     

     

     

    I try to understand the way you used it.

     

     

    You should use, i think, in this way inside Table.addcolumn funcion:

     

    List.accumulate({0..2},tbl, (s,c)=>List.AddColumn(s,  listLabel{c}, each value.metadata(table.Column(s, lstID{c})) )

     

    check the sintax and try.

    I don't have time now to go more in depth

     

     

     

     

  • v-alq-msft's avatar
    5 years ago

    Hi, Gugan_BI 

     

    As is suggested by Gugan_BI , you may use 'Table.AddColumn' function within 'List.Accumulate' function. I created data to reproduce your scenario. The pbix file is attached in the end.

    Table:

     

    Then you may add a new step with the following m codes.

    = let 
    names = Table.ColumnNames(#"Changed Type"),
    list = List.Select(names,each Text.EndsWith(_,"id")),
    re = List.Accumulate(
         list,
         #"Changed Type",
         (s,c)=>Table.AddColumn(s,c&"_label",each Value.Metadata( Table.Column(#"Changed Type",c) )[OData.Community.Display.V1.FormattedValue]?)
         
    )
    in 
    re

     

    Result:

     

    Best Regards

    Allan

     

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