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
ace_SB
Frequent Visitor

Median Measure using Distinct Values

Hi All,

 

I have a dax formula, see below, to calculate Median. It uses the scores for only selected students and ignores nulls. What I need to do is use distinct values for Score1 while calculating the Median. Is that possible? I think we can use Distinct(), but not sure where should I put that in this DAX. Thanks for your assistance.

 

MedScore = ROUND(
CALCULATE(
   medianx(FILTER(vw_ABC, vw_ABC[Score1]<> BLANK()),

              vw_ABC[Score1]) ,

           TREATAS(VALUES('vw_Option'[StuName]),vw_ABC[IStuName])
),0
)

2 ACCEPTED SOLUTIONS
Zubair_Muhammad
Community Champion
Community Champion

Hi @ace_SB

 

Try this

 

MedScore =
ROUND (
    CALCULATE (
        MEDIANX (
            FILTER ( VALUES ( vw_ABC[Score1] ), vw_ABC[Score1] <> BLANK () ),
            vw_ABC[Score1]
        ),
        TREATAS ( VALUES ( 'vw_Option'[StuName] ), vw_ABC[IStuName] )
    ),
    0
)

 

 


Regards
Zubair

Please try my custom visuals

View solution in original post

Actually this works. Thanks a lot.

View solution in original post

3 REPLIES 3
Zubair_Muhammad
Community Champion
Community Champion

Hi @ace_SB

 

Try this

 

MedScore =
ROUND (
    CALCULATE (
        MEDIANX (
            FILTER ( VALUES ( vw_ABC[Score1] ), vw_ABC[Score1] <> BLANK () ),
            vw_ABC[Score1]
        ),
        TREATAS ( VALUES ( 'vw_Option'[StuName] ), vw_ABC[IStuName] )
    ),
    0
)

 

 


Regards
Zubair

Please try my custom visuals

Actually this works. Thanks a lot.

Thanks Zubair. Use of Values() is great, but it is still not working. I need to put it in the right place. What I need is median for not null distinct values for only those students picked by the slicer using the view "vw_Option"...

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.