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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Group data, apply measure to grouped data, then average across all groups

Hi, I'm really struggling to do this. 

 

Assume I have 'Table 1', with a list of data, and this has a relationship to 'Table 2'.

Table 2 says how the data in table 1 should be grouped. This is in column Table2[groupings]

 

I want to apply a measure 'Measure1' to the grouped data. Then average over the groups. 

 

How do I do this?

I've been looking over summerize and groupby all afternoon but can't work it out. I need this done in a measure so it can update by the report level filters if someone wants to remove some data from Table1. The end goal is to apply a z score to the grouped data. 

 

Thank you for your help

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

We can try use the following measure to meet your requirement:

 

avegrouped =
AVERAGEX (
    CALCULATETABLE ( DISTINCT ( Table2[groupings] ), ALLSELECTED ( Table2 ) ),
    CALCULATE ( [Measure1] )
)

 

If it does not meet your requirement, Could you please provide a mockup sample based on fake data or describle the fields of each tables and the relations between tables simply? It will be helpful if you can show us the exact expected result based on the tables. Please upload your files to OneDrive For Business and share the link here. Please don't contain any Confidential Information or Real data in your reply.


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

I've made a very simple dataset and it's working with 

avegrouped = CALCULATE(AVERAGEX(SUMMARIZE(Table1,Table2[groupings],"meas",[Measure1]),[meas]),all(Table1))
It's not working with my real dataset, but that's not a problem with the DAX. 
Thanks for pointing me in the right direction Greg.

Hi @Anonymous ,

 

We can try use the following measure to meet your requirement:

 

avegrouped =
AVERAGEX (
    CALCULATETABLE ( DISTINCT ( Table2[groupings] ), ALLSELECTED ( Table2 ) ),
    CALCULATE ( [Measure1] )
)

 

If it does not meet your requirement, Could you please provide a mockup sample based on fake data or describle the fields of each tables and the relations between tables simply? It will be helpful if you can show us the exact expected result based on the tables. Please upload your files to OneDrive For Business and share the link here. Please don't contain any Confidential Information or Real data in your reply.


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Thanks Dong Li,

 

That's worked perfectly. The problem with summerize was that my measure was a percentage using the number of items in the group. Your calculatetable managed to cope with that, when the summerize couldn't.

Anonymous
Not applicable

Hi Greg,
I've tried this (below), and it's giving me a different value for every group (I'm not sure what it's calcuting as it's returning something different to measure for each group).
I am expecting one answer returned which is the same for every group.
 
averagegrouped =
AVERAGEX ( SUMMARIZE(Table1,Table2[groupings],"meas",[Measure1]),[meas])
 
1.png
 
amitchandak
Super User
Super User

Not Clear.

Can you share sample data and sample output.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Greg_Deckler
Super User
Super User

This looks like a measure aggregation problem. See my blog article about that here: https://community.powerbi.com/t5/Community-Blog/Design-Pattern-Groups-and-Super-Groups/ba-p/138149



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks Greg,

I'm going to go through your example now.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.