Forum Discussion

jsquaredz's avatar
jsquaredz
Icon for Advocate I rankAdvocate I
9 years ago
Solved

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...
  • Framet's avatar
    9 years ago

    Hi,

     

    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?