cancel
Showing results for
Did you mean:

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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.

1 ACCEPTED SOLUTION
Community Support

Hi @Anonymous ,

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

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

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.
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.
Community Support

Hi @Anonymous ,

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

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

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])

Super User

Not Clear.

Can you share sample data and sample output.

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

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
The Definitive Guide to Power Query (M)

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

Thanks Greg,

I'm going to go through your example now.

Announcements

#### New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

#### Power BI Monthly Update - May 2024

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

#### Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors