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
Anonymous
Not applicable

Need name of category with the most values

I have a table of clients and their genders, and I need to identify the gender with the most values, so from a table like this: 

 

Client 1 - Male

Client 2 - Male

Client 3 - Female

Client 4 - Male

Client 5 - Male

Client 6 - Male

 

I need to produce the word "Male" as a measure, because there are 5 males and only 1 female. I can't use visual filters to achieve this. 


Using RANK, I got Male = 1 and Female = 2, but I'm not sure how to take that output and produce the word "Male". 

 

What is wrong with my approach? Thank you!

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Anonymous 

Please try

Max Gender =
MAXX (
    TOPN (
        1,
        SUMMARIZE ( 'Table', 'Table'[Gender], "@Count", COUNTROWS ( 'Table' ) ),
        [@Count]
    ),
    'Table'[Gender]
)

View solution in original post

3 REPLIES 3
tamerj1
Super User
Super User

Hi @Anonymous 

Please try

Max Gender =
MAXX (
    TOPN (
        1,
        SUMMARIZE ( 'Table', 'Table'[Gender], "@Count", COUNTROWS ( 'Table' ) ),
        [@Count]
    ),
    'Table'[Gender]
)
Anonymous
Not applicable

This worked great - I was able to even add a filter on to COUNTROWS to remove blanks from consideration. Thanks so much! 

 

Didn't try the other option, that might work as well. 

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

Jihwan_Kim_0-1664987739986.png

 

 

expected result measure: =
VAR _gendertablewithcounting =
    ADDCOLUMNS (
        DISTINCT ( Data[Gender] ),
        "@count", CALCULATE ( COUNTROWS ( Data ) )
    )
VAR _groupbymaxcounting =
    GROUPBY (
        _gendertablewithcounting,
        Data[Gender],
        "@maxcount", MAXX ( CURRENTGROUP (), [@count] )
    )
RETURN
    MAXX ( _groupbymaxcounting, Data[Gender] )

 

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.


Go to My LinkedIn Page


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