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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

MEDIANX returns incomplete data compare to AVERAGEX

Hi Guys, I have this measure:

 

CalcuateData = 
var calcType = SELECTEDVALUE('Calculate By'[ComputeBy])
RETURN
SWITCH(
    TRUE(),
    calcType = "Average", AVERAGEX(VALUES(car[ExtractedDate].[Date]), CALCULATE(SUM(car[Cnt]))),
    MEDIANX(VALUES(car[ExtractedDate].[Date]),CALCULATE(SUM(car[Cnt])))
)

 

For the average, I got the result:

Daniel_Pel_0-1637580043094.png

but for the median:

Daniel_Pel_1-1637580072868.png

I only have two months. It seems like the month should be finished before having the value for median, is there a way to have the median regardless if the month is not finished?
Please see sample raw data:

TeamTypeExtractedDateCnt
Team RedSedan02/09/20213
Team RedSedan03/09/20213
Team RedSedan09/09/20213
Team RedSedan27/08/20214
Team RedHatchback08/09/20214
Team RedHatchback09/09/20215
Team RedHatchback05/11/20211
Team BlueHatchback27/08/20211
Team BlueHatchback30/08/20211
Team BlueHatchback31/08/20212
Team BlueSedan17/11/20214
Team BlueSedan18/11/20214
Team BlueSedan19/11/20214
Team BlueHatchback27/10/20211
Team YellowHatchback09/09/20216
Team YellowHatchback10/09/20215
Team YellowHatchback13/09/20214
Team YellowSedan14/09/20213


Any tips? Thank you in advance

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Try with minor changes

 

CalcuateData =
var calcType = Max('Calculate By'[ComputeBy])
RETURN
SWITCH(
TRUE(),
calcType = "Average", AVERAGEX(VALUES(car[ExtractedDate]), CALCULATE(SUM(car[Cnt]))),
MEDIANX(VALUES(car[ExtractedDate]),CALCULATE(SUM(car[Cnt])))
)

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

@amitchandak Thank you! it works! 

amitchandak
Super User
Super User

@Anonymous , Try with minor changes

 

CalcuateData =
var calcType = Max('Calculate By'[ComputeBy])
RETURN
SWITCH(
TRUE(),
calcType = "Average", AVERAGEX(VALUES(car[ExtractedDate]), CALCULATE(SUM(car[Cnt]))),
MEDIANX(VALUES(car[ExtractedDate]),CALCULATE(SUM(car[Cnt])))
)

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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