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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

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]
    )

 

 

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]
    )

 

 

Thank you so much. This works!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors