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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
efanta
Frequent Visitor

How to calculate a sum of averages of specific items

Hi Folks,

 

 

I´m trying to calculate the sum of different averages of elements that have an assigned criterion. I will explain it in an example that I prepared:

 

For different branches (A to J) od a company, I must add the averages of each one only if they have had at least 3 sales during the year (in the table appear at least 3 times). For this case, I have to add the average sales of A and the average sales of B.

 

MonthNameSales
Jan-17A12
Jan-17B14
Jan-17C2
feb-17E3
feb-17F5
feb-17A16
feb-17B22
mar-17H54
mar-17A11
mar-17B34
mar-17J44

 

 

I have tried many formulas but I can not reach the value! 

 

The result should be:

 

Criteria - Count>=3
 A - Average13
 B - Average23,33
sum A av + B av36,33

 

 

Please, if someone manages to help me, I will be grateful!

1 ACCEPTED SOLUTION
MarcelBeug
Community Champion
Community Champion

Solution in Power Query (M).

 

You can use group by on the Transform tab and fill out the popup:

 

Group By for Sum Averages.png

Note: if you have data of multiple years, then you should add a group for the year as well.

Then filter on Count >= 3 and remove the Count; example code:.

 

let
    #"Grouped Rows" = Table.Group(SalesData, {"Name"}, {{"Count", each Table.RowCount(_), type number}, {"Average", each List.Average([Sales]), type number}}),
    #"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each [Count] >= 3),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Count"})
in
    #"Removed Columns"

 

Result in a Matrix visual:

Group By for Sum Averages Matrix.png

Specializing in Power Query Formula Language (M)

View solution in original post

1 REPLY 1
MarcelBeug
Community Champion
Community Champion

Solution in Power Query (M).

 

You can use group by on the Transform tab and fill out the popup:

 

Group By for Sum Averages.png

Note: if you have data of multiple years, then you should add a group for the year as well.

Then filter on Count >= 3 and remove the Count; example code:.

 

let
    #"Grouped Rows" = Table.Group(SalesData, {"Name"}, {{"Count", each Table.RowCount(_), type number}, {"Average", each List.Average([Sales]), type number}}),
    #"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each [Count] >= 3),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Count"})
in
    #"Removed Columns"

 

Result in a Matrix visual:

Group By for Sum Averages Matrix.png

Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors