Forum Discussion

Simon_29's avatar
Simon_29
Helper II
4 years ago
Solved

Sumif with condition

Hi everybody, I have the following problem in Power Query. I would need to create a function that would add the values ​​in the Order Amount column and divide them by the value in the TD exract co...
  • v-jingzhang's avatar
    4 years ago

    Hi Simon_29 

     

    Use the Group by feature under Transform tab. Then select the Sum Order Amount column and divide it by TD extract Sum column. 

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lYzBCQAhDAR7yVskuzEaaxH7b+OMcHDfewwM7LBrCbqpo7WQIkygQOW4Cut1qskuP8Jw0s0jFyRQj6ijp7PRjwdvOh0c3VXfdFjTWXV+/Pzs/QA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"SCP Order Number" = _t, Count = _t, #"Order Amount" = _t, #"TD extract (Order info).Sum" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"SCP Order Number", Int64.Type}, {"Count", Int64.Type}, {"Order Amount", type number}, {"TD extract (Order info).Sum", type number}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"SCP Order Number", "Count"}, {{"Sum Order Amount", each List.Sum([Order Amount]), type nullable number}, {"TD extract Sum", each List.Max([#"TD extract (Order info).Sum"]), type nullable number}}),
        #"Inserted Division" = Table.AddColumn(#"Grouped Rows", "Division", each [Sum Order Amount] / [TD extract Sum], type number)
    in
        #"Inserted Division"

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.