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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
skempson
New Member

DATEDIFF question

Hi - 

I am trying to calculate the difference between 2 dates and this is working to a certain point.

 

DaytoEnd = IF(ISBLANK(SUM(proj_assessmentSet[ems_datecompleted])), 0, 1.0* SUM(proj_assessmentSet[ems_datecompleted]) - SUM(proj_assessmentSet[proj_StartDate]))

 

However, some dates are showing 0 even when there are 2 valid dates. Example:

7/07/2013 16:00 -  30/03/2016 7:31 = 997 (correct)

3/07/2013 16:00  - 25/02/2016 3:54 = 0 (incorrect)

In Excel the datedif function fro the second example give the correct value of 967.

 

Any ideas?

1 REPLY 1
Anonymous
Not applicable

Hi skempson,

 

Based on test, it works well on my side, below is the test steps.

 

  1. Create a date table.( date Between 2000~ today)

Excel formula:

DateStart =RANDBETWEEN(DATE(2000,1,1),TODAY())

DateEnd =A2+RANDBETWEEN(1,IF((YEAR(TODAY())-YEAR(A2))*365>0,(YEAR(TODAY())-YEAR(A2))*365,1))

 

Capture6.PNG

 

  1. Test formulas.

 

Calculate column:

DateDiff =

VAR minDate=MIN([DateStart],[DateEnd])

VAR maxDate=MAX([DateStart],[DateEnd])

return

DATEDIFF(minDate,maxDate,DAY)

 

Measures:

DaytoEnd =IF(ISBLANK(SUM(Sheet1[DateEnd])), 0, 1.0* SUM(Sheet1[DateEnd]) - SUM(Sheet1[DateStart]))

 

Diff = DATEDIFF(MIN(VALUES(Sheet1[DateStart]),VALUES(Sheet1[DateEnd])) ,MAX(VALUES(Sheet1[DateStart]),VALUES(Sheet1[DateEnd])) ,DAY)

 

Result:

 Capture5.PNG

 

Since I can’t reproduce your issue, can you share us a pbix file?

 

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.