Forum Discussion

dolevh's avatar
dolevh
Helper II
5 years ago
Solved

Query from Excel to PBI

Hey,

I Just want to add a column to my table but I don't know how to write it on PBI. 

thanks for everything. 

 

  • Hi  dolevh,

     

    Using below M code:

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjYwUNJRMjLUdSwoAjJMLYyUYnWilUywCMcCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Hours = _t, Month = _t, ID = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Hours", Int64.Type}, {"ID", Int64.Type}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Epic %", each [Hours]/List.Sum(Table.SelectRows(#"Changed Type",(x)=>x[Month]=[Month] and x[ID]=[ID])[Hours])),
        #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Epic %", Percentage.Type}})
    in
        #"Changed Type1"

     

     

    And you will see:

     

     

    Check my .pbix file attached.

     

    Best Regards,
    Kelly

    Did I answer your question? Mark my reply as a solution!

3 Replies

  • dolevh 

    Do you need it as Power Query or DAX solution? 


    paste your sample data and the expected result from Excel in your reply


    • v-kelly-msft's avatar
      v-kelly-msft
      Community Support

      Hi  dolevh,

       

      Using below M code:

       

      let
          Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjYwUNJRMjLUdSwoAjJMLYyUYnWilUywCMcCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Hours = _t, Month = _t, ID = _t]),
          #"Changed Type" = Table.TransformColumnTypes(Source,{{"Hours", Int64.Type}, {"ID", Int64.Type}}),
          #"Added Custom" = Table.AddColumn(#"Changed Type", "Epic %", each [Hours]/List.Sum(Table.SelectRows(#"Changed Type",(x)=>x[Month]=[Month] and x[ID]=[ID])[Hours])),
          #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Epic %", Percentage.Type}})
      in
          #"Changed Type1"

       

       

      And you will see:

       

       

      Check my .pbix file attached.

       

      Best Regards,
      Kelly

      Did I answer your question? Mark my reply as a solution!