Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
Hi,
I have a requirement to calculate mean and median between the two dates. Please find sample data below:
Protocol | Submit Date | Intake Date | New calcualted column for datediff |
190 | 04/05/2019 | 04/03/2019 | 2 |
191 | 07/01/2019 | 06/04/2019 | 27 |
201 | 07/05/2022 | 06/30/2022 | 5 |
204 | 08/02/2022 | 06/14/2022 | 49 |
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.
Could you please suggest on how to fix this using DAX.
Thank you
Solved! Go to Solution.
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)
Similar code but use MEDIANX using the table and the mindiff
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?
Thanks for posting pbix. This would be unsolveable without it.
Here is data in pbix:
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
Can you provide your pbix please?
@HotChilli
Please find the pbix file here
https://drive.google.com/file/d/1aA4akdyBqRjK8JRALQa3VmEgnnpqr25u/view?usp=share_link
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.