Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Difference column in a matrix

Hi,

i'd calculate the difference in a matrix between values from the same column [HRS_PLAN_DELTA], for each IDS in the same date, for different ID_Report.

Do you have some ideas ? 

Dom

  • Hi Anonymous ,

     

    To pivot the table and add a custom column in power query can get the excepted result we need. M code for your refernce.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc7LCUAhDETRXrIWdEafn1rE/ttQwgskCyFwSK57CwhJoi8js2C98ZOTjKhEo+6oKlWj6agpNSPgN+r1EAOd9VjDcDZizq/NmHs/ORc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t, IDS = _t, Date = _t, HRS_PLAN_DELTA = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"IDS", Int64.Type}, {"Date", type date}, {"HRS_PLAN_DELTA", Int64.Type}}),
        #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"IDS"}),
        #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Removed Columns", {{"ID", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Removed Columns", {{"ID", type text}}, "en-US")[ID]), "ID", "HRS_PLAN_DELTA", List.Sum),
        #"Added Custom" = Table.AddColumn(#"Pivoted Column", "Custom", each [121]-[122])
    in
        #"Added Custom"

     

    Regards,

    Frank

7 Replies