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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
BUserTG
Frequent Visitor

Group by and count by the maximum attribute from the group

I am looking to write a DAX calculation that allows me to count by the number of groupings based on the max of one of the attributes of the group. Example data below where there's a group with items inside of it and each item has its own value. I want to count the unique groups that fall into each attribute, based on what the max attribute is of the group. All three below are columns.

GroupItemAttributeValue
Group1A3
Group1B3
Group1C2
Group2X1
Group2Y2
Group2Z3
Group3Q1
Group3A1

 

Then the result I want to produce is a distinct count of groups for each attribute. For example, in the above there are two groups which would fall into Attribute "3" and one group would fall into Attribute "1". Group 1s max is 3, Group 2s max is 3, and Group 3s max is 1. So the visual I need to create would be:

AttributeGroupCount
11
20
32

 

Effectively, I need to be able to bucket each of the groups by the MAX(Attribute) and then count them plus do % of total visualizations so I can see the distribution of the groups by their max item. This also needs to be dynamic as all the columns can be filtered and the count would need to be re-calculated.

 

Thanks.

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi, @BUserTG 

Please check the below picture and the sample pbix file's link down below.

 

Picture2.png

Group Count =
VAR maxattribute =
MAX ( 'Table'[AttributeValue] )
VAR grouptable =
GROUPBY (
ALL ( 'Table' ),
'Table'[Group],
"@maxattribute", MAXX ( CURRENTGROUP (), 'Table'[AttributeValue] )
)
VAR filtergrouptable =
FILTER ( grouptable, [@maxattribute] = maxattribute )
RETURN
COALESCE ( COUNTROWS ( filtergrouptable ), 0 )
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi, @BUserTG 

Please check the below picture and the sample pbix file's link down below.

 

Picture2.png

Group Count =
VAR maxattribute =
MAX ( 'Table'[AttributeValue] )
VAR grouptable =
GROUPBY (
ALL ( 'Table' ),
'Table'[Group],
"@maxattribute", MAXX ( CURRENTGROUP (), 'Table'[AttributeValue] )
)
VAR filtergrouptable =
FILTER ( grouptable, [@maxattribute] = maxattribute )
RETURN
COALESCE ( COUNTROWS ( filtergrouptable ), 0 )
 
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Thanks @Jihwan_Kim . This does work except in the case of filtering. For example, if I applied a filter on the Item column, I would want the results to dynamically change. So if I filtered [Item] = 2 then the resultant table should be:

AttributeValue  GroupCount
1                        0
2                        1
3                        0

I've tried using an ALLEXCEPT() in the GROUPBY() but that did not work. Any idea on how to make the calculation resilient to filtering on the source table?

Thanks.

ALLSELECTED() should do the trick, seems to be working. Thanks.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.