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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
konwes97
Frequent Visitor

Wrong calculation of the medianX

Hello everyone, here I am counting weighted averages based on member data. The problem is that if I have empty values then my function takes into account these members and therefore calculations are not correct.

//
MEDIANX
(SUMMARIZE('2021','2021'[SMI_CODE],"Comp1 AVG",
CALCULATE(AVERAGE('2021'[COMP3TGT]),'2021'[COMP3TGT]>0)),[Comp1 AVG])
//

As you can see on my code I've applied to count only for member where value is >0.

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

HI @konwes97,

Perhaps you can try to add this filter on your parameter table to exclude these not match records before calculations:

formula =
MEDIANX (
    SUMMARIZE (
        FILTER ( '2021' , '2021'[COMP3TGT] > 0 ),
        '2021'[SMI_CODE],
        "Comp1 AVG", AVERAGE ( '2021'[COMP3TGT] )
    ),
    [Comp1 AVG]
)

If the above formula does not help, please share more detailed information to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
JanaP
Helper I
Helper I

Hello,

 

I am using the formula above, however, some of the values are being ignored and therefore the medianx returns the wrong value. 

I have a 3 tables that is filtered by the user via a slicer. They are copies of the same source, I am using SUMX, AVERAGEX and MEDIANX respectively, all works fine in the first two, only MEDIANX is ignoring some, sometimes all values, depending on the slicer selection.

 

Here is the formula:

    MEDIANX(
        SUMMARIZE(                                          
            'fct_table',
            'fct_table'[Column_1],        
            'fct_table'[Column_2],                  //primary key for this column is in the slicer, relationship is fine
            "Correct Total",[my_measure]      //my measure is a sum with a filter on the date table
            ),
            [Correct Total]                                 
    )
 
Where am I going wrong? Why does this work for SUMX and AVERAGEX and not for MEDIANX?
 
Can somebody help me fix this please?
Thanks a lot, it is driving me mad... 
v-shex-msft
Community Support
Community Support

HI @konwes97,

Perhaps you can try to add this filter on your parameter table to exclude these not match records before calculations:

formula =
MEDIANX (
    SUMMARIZE (
        FILTER ( '2021' , '2021'[COMP3TGT] > 0 ),
        '2021'[SMI_CODE],
        "Comp1 AVG", AVERAGE ( '2021'[COMP3TGT] )
    ),
    [Comp1 AVG]
)

If the above formula does not help, please share more detailed information to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
amitchandak
Super User
Super User

@konwes97 , Check for non blank too

MEDIANX(SUMMARIZE('2021','2021'[SMI_CODE],"Comp1 AVG",
CALCULATE(AVERAGE('2021'[COMP3TGT]),'2021'[COMP3TGT]>0 && not(isblank([COMP3TGT])))),[Comp1 AVG])

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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