cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
PowerrrBrrr
Helper III
Helper III

How to get the maximum occurence for a category

I have table like this 

SubjectStatus
MathPass
MathPass
English Fail
English Pass
Math Pass
Hindi Fail
HindiFail
Math Fail

 

I need to list the subject which has maximum "Pass". i.e. here Math should appear in my Visual as it appeard 3 times

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

Hi @PowerrrBrrr ,

Please refer to my pbix file to see if it helps you.

Create two measures.

_count =
CALCULATE (
    COUNT ( 'Table'[Status] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Subject] = SELECTEDVALUE ( 'Table'[Subject] )
            && 'Table'[Status] = "Pass"
    )
)
Measure_2 =
VAR _maxvalue =
    MAXX ( ALL ( 'Table' ), [_count] )
RETURN
    IF (
        [_count] = _maxvalue,
        MAX ( 'Table'[Subject] ) & " " & _maxvalue,
        BLANK ()
    )

vpollymsft_0-1656991684484.png

 

If I have misunderstood your meaning, please provide more details with your desired output.

 

Best Regards
Community Support Team _ Polly

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

4 REPLIES 4
v-rongtiep-msft
Community Support
Community Support

Hi @PowerrrBrrr ,

Please refer to my pbix file to see if it helps you.

Create two measures.

_count =
CALCULATE (
    COUNT ( 'Table'[Status] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Subject] = SELECTEDVALUE ( 'Table'[Subject] )
            && 'Table'[Status] = "Pass"
    )
)
Measure_2 =
VAR _maxvalue =
    MAXX ( ALL ( 'Table' ), [_count] )
RETURN
    IF (
        [_count] = _maxvalue,
        MAX ( 'Table'[Subject] ) & " " & _maxvalue,
        BLANK ()
    )

vpollymsft_0-1656991684484.png

 

If I have misunderstood your meaning, please provide more details with your desired output.

 

Best Regards
Community Support Team _ Polly

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

 

johnt75
Super User
Super User

You can create a measure like 

Top subject = 
var summaryTable = ADDCOLUMNS( VALUES('Table'[Subject]), 
    "@num passes", 
    CALCULATE( COUNTROWS('Table'),'Table'[Status] = "Pass")
)
return CONCATENATEX( TOPN(1, summaryTable, [@num passes]), [Subject], ", ")

In the event that there are 2 or more subjects with the same number of passes this will return a comma separated list of all of them

What is @num passes for. I tried and i get error as Column 'Subject' cannot be found or may not be used in this expression

[@num passes] is used to rank the summary table, so that you can get the top one. If you've changed the 'Table'[Subject] to match the proper table and column name from your model then just change the [Subject] column in the CONCATENATEX to match the column name from your model.

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors