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

Filter out 0/Negative/Null values when calculating Median

Hi, I have a calculation for median that is built from this formula.

 

Median Latency Test =
VAR NumValuesHalved = COUNT ( Query2[Latency] ) / 2
RETURN
MINX (
FILTER (
VALUES ( Query2[Latency]),
CALCULATE (
COUNT ( Query2[Latency]),
Query2[Latency] <= EARLIER ( Query2[Latency] )
)
< NumValuesHalved
),
Query2[Latency]
)

 

I am wondering how to alter this formula to filter out 0/negative/null values so that they are  not utilized in the calculation of Median Latency. Can anyone help with this?

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

Hi @Artemis1254

 

Give this a try

 

Median Latency Test =
VAR NumValuesHalved =
    COUNT ( Query2[Latency] ) / 2
RETURN
    MINX (
        FILTER (
            VALUES ( Query2[Latency] ),
            Query2[Latency] > 0
                && CALCULATE (
                    COUNT ( Query2[Latency] ),
                    Query2[Latency] <= EARLIER ( Query2[Latency] )
                )
                    < NumValuesHalved
        ),
        Query2[Latency]
    )

 

 


Regards
Zubair

Please try my custom visuals

View solution in original post

2 REPLIES 2
Zubair_Muhammad
Community Champion
Community Champion

Hi @Artemis1254

 

Give this a try

 

Median Latency Test =
VAR NumValuesHalved =
    COUNT ( Query2[Latency] ) / 2
RETURN
    MINX (
        FILTER (
            VALUES ( Query2[Latency] ),
            Query2[Latency] > 0
                && CALCULATE (
                    COUNT ( Query2[Latency] ),
                    Query2[Latency] <= EARLIER ( Query2[Latency] )
                )
                    < NumValuesHalved
        ),
        Query2[Latency]
    )

 

 


Regards
Zubair

Please try my custom visuals

Thank you so much. This works!

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.