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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
POSPOS
Post Partisan
Post Partisan

Incorrect Mean and Median Values using DAX

Hi,

I have a requirement to calculate mean and median between the two dates. Please find sample data below:

ProtocolSubmit DateIntake DateNew calcualted column for datediff
19004/05/201904/03/20192
19107/01/201906/04/201927
20107/05/202206/30/20225
20408/02/202206/14/202249

 

I have created a new calculated column to calculate the datediff between the two dates using DATEDIFF.

Then I have created a new measure to calculate the mean of the days:

 

 

 

Average(New calcualted column for datediff)

 

 

 

This is giving 17 as result intead of 20.75 (83/4)

 

Median

 

 

 

Median(New calculated column for datediff)

 

 

 

 This is giving 5 as result intead of 16.

Screenshot .png

 

Could you please suggest on how to fix this using DAX.

 

Thank you

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

I think you should be a bit careful with that table visual.  It doesn't have any aggregations so in a way it's a kind of false table because the 190 row actually represents 2 rows which no-one would know unless they looked at the whole data.

Because of this 'false' table it will take a measure like this to get the average you want

MeasureX = var _summTab = SUMMARIZECOLUMNS('data1111 (2)'[Protocol Number], 'data1111 (2)'[Intake Date], data1111[First_SubmitDate], "MinDiff", MIN(data1111[Datediff]))
var _RowCount = COUNTROWS(_summTab)
var _SumTotal = SUMX(_summTab, [MinDiff])
RETURN
DIVIDE(_SumTotal, _RowCount)

 

View solution in original post

7 REPLIES 7
HotChilli
Super User
Super User

Similar code but use MEDIANX using the table and the mindiff

https://learn.microsoft.com/en-us/dax/medianx-function-dax 

HotChilli
Super User
Super User

I think you should be a bit careful with that table visual.  It doesn't have any aggregations so in a way it's a kind of false table because the 190 row actually represents 2 rows which no-one would know unless they looked at the whole data.

Because of this 'false' table it will take a measure like this to get the average you want

MeasureX = var _summTab = SUMMARIZECOLUMNS('data1111 (2)'[Protocol Number], 'data1111 (2)'[Intake Date], data1111[First_SubmitDate], "MinDiff", MIN(data1111[Datediff]))
var _RowCount = COUNTROWS(_summTab)
var _SumTotal = SUMX(_summTab, [MinDiff])
RETURN
DIVIDE(_SumTotal, _RowCount)

 

@HotChilli  - I am now getting accurate results for average.
I tried to use the same code to derive median. Could you also help with that?

HotChilli
Super User
Super User

Thanks for posting pbix.  This would be unsolveable without it.

Here is data in pbix:

Screenshot 2023-10-23 201434.png

average = 85/5 = 17

@HotChilli 
Thanks for pointing this out. 
As I am picking the first date whenever there are more than one dates for a protocol, (this is attached in the pbix),is there a way I can get the desired results:
Average = 83/4 as 20.75 
Median = 16

HotChilli
Super User
Super User

Can you provide your pbix please?

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.