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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
ngct1112
Post Patron
Post Patron

How to count the MAX number of Group and find which group

Hi,

 

I am trying to figure out how to find the Highest count of each group. Simplified data as below

From this table, we can find that there are 

7 items in Group A

3 items in Group B

9 items in Group C

 

Items

Group

1

A

2

A

3

A

4

C

5

C

6

A

7

C

8

C

9

A

10

A

11

C

12

A

13

C

14

C

15

B

16

B

17

C

18

B

19

C

 

Is it possible I could write 2 measures to find out 

1.) Most items' Group: C

2.) Highest Items: 9

 

Appreciate your help!

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@ngct1112 , Create two measures like

 

Top 1 count = CALCULATE(calculate(count(Table[Group])),TOPN(1,all(Table[Group]),calculate(count(Table[Group])),DESC),VALUES(Table[Group]))

Top 1 Group = CALCULATE(calculate(max(Table[Group])),TOPN(1,all(Table[Group]),calculate(count(Table[Group])),DESC),VALUES(Table[Group]))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

CNENFRNL
Community Champion
Community Champion

Hi, @ngct1112 , you might want to use the following measures,

 

Group = 
VAR __sum =
    ADDCOLUMNS (
        SUMMARIZE ( Table1, Table1[Group] ),
        "Count", CALCULATE ( COUNTROWS ( Table1 ) )
    )
RETURN
    MAXX ( TOPN ( 1, __sum, [Count] ), Table1[Group] )
Most Items = 
VAR __sum =
    ADDCOLUMNS (
        SUMMARIZE ( Table1, Table1[Group] ),
        "Count", CALCULATE ( COUNTROWS ( Table1 ) )
    )
RETURN
    MAXX ( __sum, [Count] )

 

Screenshot 2021-01-04 121230.png

 

 

Btw, Power Query easily does the trick,

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Rc2xEYAgFIPhXVJTGFGEUh3jHfuvIchd0n33p0gEiIQbPQV2KUvH0PvrlIrWS61KTSs3k9rpG2ZXH3E+PYvF9Bera1u1fw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Items = _t, Group = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Group"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each [Count] = List.Max(#"Grouped Rows"[Count]))
in
    #"Filtered Rows"

Screenshot 2021-01-04 122432.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

Hi, @ngct1112 , you might want to use the following measures,

 

Group = 
VAR __sum =
    ADDCOLUMNS (
        SUMMARIZE ( Table1, Table1[Group] ),
        "Count", CALCULATE ( COUNTROWS ( Table1 ) )
    )
RETURN
    MAXX ( TOPN ( 1, __sum, [Count] ), Table1[Group] )
Most Items = 
VAR __sum =
    ADDCOLUMNS (
        SUMMARIZE ( Table1, Table1[Group] ),
        "Count", CALCULATE ( COUNTROWS ( Table1 ) )
    )
RETURN
    MAXX ( __sum, [Count] )

 

Screenshot 2021-01-04 121230.png

 

 

Btw, Power Query easily does the trick,

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Rc2xEYAgFIPhXVJTGFGEUh3jHfuvIchd0n33p0gEiIQbPQV2KUvH0PvrlIrWS61KTSs3k9rpG2ZXH3E+PYvF9Bera1u1fw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Items = _t, Group = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Group"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each [Count] = List.Max(#"Grouped Rows"[Count]))
in
    #"Filtered Rows"

Screenshot 2021-01-04 122432.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

amitchandak
Super User
Super User

@ngct1112 , Create two measures like

 

Top 1 count = CALCULATE(calculate(count(Table[Group])),TOPN(1,all(Table[Group]),calculate(count(Table[Group])),DESC),VALUES(Table[Group]))

Top 1 Group = CALCULATE(calculate(max(Table[Group])),TOPN(1,all(Table[Group]),calculate(count(Table[Group])),DESC),VALUES(Table[Group]))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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