Forum Discussion
Calculating the difference between two dates
- 3 years ago
Hey dineshj23 ,
the following screenshot shows my sample data and also the result:
Here is the DAX statement to create the Calculated Column:
timeline = var StartDate = 'Table'[start date] var CompletedDateIsMissing = IF( ISBLANK( 'Table'[completed date] ) , 1 , 0) return SWITCH( CompletedDateIsMissing , 0 , var __DateDiff = DATEDIFF( StartDate , 'Table'[completed date] , DAY ) return IF( __DateDiff < 30 , "On time" , "Late" ) , 1 , var DateToday = TODAY() var __DateDiff = DATEDIFF( StartDate , DateToday , DAY ) return IF( __DateDiff < 30 , "On time" , "Pending Late" ) )I branch the decision-making by using SWITCH (completed date is missing or not). In both cases I calculate the number of days and return a value.
Hopefully, this what you are looking for.Regards,
Tom
Hey dineshj23 ,
the following screenshot shows my sample data and also the result:
Here is the DAX statement to create the Calculated Column:
timeline =
var StartDate = 'Table'[start date]
var CompletedDateIsMissing = IF( ISBLANK( 'Table'[completed date] ) , 1 , 0)
return
SWITCH(
CompletedDateIsMissing
, 0
, var __DateDiff = DATEDIFF( StartDate , 'Table'[completed date] , DAY )
return
IF( __DateDiff < 30 , "On time" , "Late" )
, 1
, var DateToday = TODAY()
var __DateDiff = DATEDIFF( StartDate , DateToday , DAY )
return
IF( __DateDiff < 30 , "On time" , "Pending Late" )
)
I branch the decision-making by using SWITCH (completed date is missing or not). In both cases I calculate the number of days and return a value.
Hopefully, this what you are looking for.
Regards,
Tom
- dineshj233 years agoHelper I
Hi TomMartens, How can I see if there's completed date missing but it's less than 30 days from Today and to label it as "Pending On time?
Thank you.
- TomMartens3 years agoSuper User
Hey dineshj23 ,
just change this part
, 1 , var DateToday = TODAY() var __DateDiff = DATEDIFF( StartDate , DateToday , DAY ) return IF( __DateDiff < 30 , "On time" , "Pending Late" ) )to this
, 1 , var DateToday = TODAY() var __DateDiff = DATEDIFF( StartDate , DateToday , DAY ) return IF( __DateDiff < 30 , "Pending On time" , "Pending Late" ) )Regards,
Tom