Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Help: Sum with multiple conditions

Hi,

 

I am trying to sum quantity based on strategy and movement shown in table below. For example, sum the quantity for movement 601 & 202 for each strategy. 

 

So Strategy AAD should be a total of -467 and 80; Srategy AAP should be a total of -573305 and 2200.

 

Any help would be appreciated. 

 

sharon_17_0-1641439603453.png

 

3 REPLIES 3
jennratten
Super User
Super User

Hello - you could filter the table for the Movements to be summed, then group the table and sum to Quantity and Cost.

 

BEFORE

jennratten_1-1641484823315.png

 

 

AFTER

jennratten_0-1641484813644.png

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Tcw7CsAgEIThu2xtYFz3YSvkAOnF+19DiSZsM8UH8/dOrd2UKCOvNVGlkT60Fy8xD8jgtRWHnv9cDdWDnrd6KdDgKmU7JEZ2lxkLxwQ=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Strategy = _t, Movement = _t, Quantity = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Strategy", type text}, {"Movement", Int64.Type}, {"Quantity", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Movement] = 202 or [Movement] = 601)),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Strategy"}, {{"Quantity Sum", each List.Sum([Quantity]), type nullable number}})
in
    #"Grouped Rows"

 

If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.

Proud to be a Microsoft Fabric Super User

Anonymous
Not applicable

Thanks @jennratten. Because I have a list of movement calculations and also strategy may not have all of the movements. For example, I would need to calculate movement 601+981, and 101 for each strategy shown below.

StrategyMovementQuantity
AAD6011
AAD9812
AAP6013
AAP9814
AAP 1015

 

So, it should be 

StrategyMovement Quantity
AAD601/9813
AAP601/9817
AAD 1010
AAD1015

 

AAD doesn't have 101 movement so it should be zero, and would need to print all different movement calculations. I am thinking two loops - not sure if Power Query could do that. Open to another simplified way.

Based on this info, I think it would be best to create a mapping table that shows how the Movements should be grouped.  Since group should be summed for each Strategy we can omit Strategy from the mapping table.  Something like the snip below, where each Movement is listed along with a group number.  All Movements with the same group number will be added together.

 

jennratten_0-1641490843371.png

 

If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.

Proud to be a Microsoft Fabric Super User

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.