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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

DAX to calculate count distinct players based max score

Hi All,

 

I need some help to build dax query. 

I have a table like this

day player score
23/jun 1 3
23/jun 2 3
23/jun 3 4
24/jun 2 4
25/jun 1 5

 
I want to calculate a measure that depending on the date filter, retrieves the count distinct of players with max score, something like this:
Date filter: between 23 and 24of jun

scorecountdistinct(player) where max score equal to 
10
20
31
42
50

or

Date filter: between 23 and 25of jun

scorecountdistinct(player) where max score equal to 
10
20
30
42
51

 

This was my inicial measure query, but the results aren't accurate...

# Users achieved max score =
VAR MAXScore = MAX('Table'[Score])
VAR COUNTDIST = DISTINCTCOUNT('Table'[player])

RETURN
CALCULATE(COUNTDIST, MAXSTREAK='Table'[score])

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

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

Create a table first.

Table 2 = SUMMARIZE('Table','Table'[ score])

Then create two measures.

Measure =
VAR _maxdate =
    CALCULATE ( MAX ( 'Table'[day] ), ALLSELECTED ( 'Table' ) )
VAR _mindate =
    CALCULATE ( MIN ( 'Table'[day] ), ALLSELECTED ( 'Table' ) )
VAR _countrows =
    CALCULATE (
        MAX ( 'Table'[ score] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[ player] = SELECTEDVALUE ( 'Table'[ player] )
                && 'Table'[day] >= _mindate
                && 'Table'[day] <= _maxdate
        )
    )
RETURN
    _countrows
Measure_2 =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[ player] ),
    FILTER ( ( 'Table' ), [Measure] = SELECTEDVALUE ( 'Table 2'[ score] ) )
)

vpollymsft_0-1656383796947.png

vpollymsft_1-1656383825114.png

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

2 REPLIES 2
Anonymous
Not applicable

Hi @Anonymous ,

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

Create a table first.

Table 2 = SUMMARIZE('Table','Table'[ score])

Then create two measures.

Measure =
VAR _maxdate =
    CALCULATE ( MAX ( 'Table'[day] ), ALLSELECTED ( 'Table' ) )
VAR _mindate =
    CALCULATE ( MIN ( 'Table'[day] ), ALLSELECTED ( 'Table' ) )
VAR _countrows =
    CALCULATE (
        MAX ( 'Table'[ score] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[ player] = SELECTEDVALUE ( 'Table'[ player] )
                && 'Table'[day] >= _mindate
                && 'Table'[day] <= _maxdate
        )
    )
RETURN
    _countrows
Measure_2 =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[ player] ),
    FILTER ( ( 'Table' ), [Measure] = SELECTEDVALUE ( 'Table 2'[ score] ) )
)

vpollymsft_0-1656383796947.png

vpollymsft_1-1656383825114.png

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.

Anonymous
Not applicable

Hi , i am not sure but this may be help you

 

Measure 2 = 
var _table=SUMMARIZE('Table','Table'[player],'Table'[Date],"distinctcount",DISTINCTCOUNT(MAX('Table'[score]))) return SUMX(_table,[distinctcount])

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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