Showing results for 
Search instead for 
Did you mean: 
Advocate I
Advocate I

Datediff start date cannot be greater than the end date

I have been using DAX DATEDIFF statement  to calculate No Days between two dates which are

Target Completion Date and Actual Completion Date


Which works all very well except now I have sometimes the Actual Completion Date is before the Target Completion Date (ie where an Action Officer performed better and completed the task before the "target" date).


However, of course, DATEDIFF doesn't like this and gives error "In DATEDIFF function, the start date cannot be greater than the end date"


Why can't this Dax function just return the negative value in this case?  Is there a way we can enhance this function to return a signed integer?

Resolver II
Resolver II



Whilst I can't answer the "why" it can't return a negative integer for dates where the start date is after the end date I can suggest you could simply handle it with a IF statement. Test your dates if the start date is greater than the end date then change the sign of the result datediff with the dates passed to the function the other way round.

DateDiffMeasure :=
IF (
    [StartDateField] > [EndDateField],
    0 - DATEDIFF ( [EndDateField], [StartDateField], DAY ),
    DATEDIFF ( [StartDateField], [EndDateField], DAY )

Might work for you?

View solution in original post


Helpful resources


Happy New Year from Power BI

This is a must watch for a message from Power BI!

December Update

Check it Out!

Click here to read more about the December 2020 Updates!

Community Blog

Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors