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

MAXX of Category based on DistinctCount of rows

Hi, 
I have a sample data below. What I'm trying to do is show the State which has the Max value of rows based on the distinct count of IDs.
Answer = West, which has 4 IDs count
I know how to show the value 4, but not the State = West. 
My code:


DistinctCount = DISTINCTCOUNT(Table[ID])
Max Value = MAXX(values(Table[State]),[DistinctCount])

IDState
AWest
BWest
CEast
DNorth
EWest
FWest
GEast


Can anyone help me with bringing out the value "West"?

Thank you.

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous ,

 

I have checked Jihwan_Kim's code, I think his measure will alway return "West", due to it will return the max state.

My Sample:

RicoZhou_0-1673511525263.png

The max state in my sample should be "East".

 

State name max count: =
VAR _MaxCount =
    MAXX ( VALUES ( 'Table'[State] ), [DistinctCount] )
RETURN
    MAXX (
        FILTER ( VALUES ( 'Table'[State] ), [DistinctCount] = _MaxCount ),
        [State]
    )

 

Result in my sample is as below.

RicoZhou_1-1673511869355.png

Test by your data, result should return "West".

RicoZhou_2-1673511916589.png

RicoZhou_3-1673511924836.png

 

Best Regards,
Rico Zhou

 

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

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous ,

 

I have checked Jihwan_Kim's code, I think his measure will alway return "West", due to it will return the max state.

My Sample:

RicoZhou_0-1673511525263.png

The max state in my sample should be "East".

 

State name max count: =
VAR _MaxCount =
    MAXX ( VALUES ( 'Table'[State] ), [DistinctCount] )
RETURN
    MAXX (
        FILTER ( VALUES ( 'Table'[State] ), [DistinctCount] = _MaxCount ),
        [State]
    )

 

Result in my sample is as below.

RicoZhou_1-1673511869355.png

Test by your data, result should return "West".

RicoZhou_2-1673511916589.png

RicoZhou_3-1673511924836.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1673471709418.png

 

 

State name max count: =
MAXX (
    GROUPBY (
        ADDCOLUMNS ( VALUES ( 'Table'[State] ), "@count", [DistinctCount] ),
        'Table'[State],
        "@maxcount", MAXX ( CURRENTGROUP (), [@count] )
    ),
    'Table'[State]
)

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

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.