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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
dineshj23
Helper I
Helper I

Calculating the difference between two dates

Hi. I have two dates in my workbook; start and completed date. I am calculating the difference between the two dates. If the difference is less than 30 days, it's "On Time". If the difference is more than 30 days, then it's "Late". How do I calculate the ones that are running late that don't have the completed date but only the start date. We can use today's date to calculate how late it is. 
 
Below is the code I have so far. 
 
Q Timeline = Switch(true(),ISBLANK('FPS selection'[O to C]), "No Value",                                                                                               'FPS selection'[O to C] <= 30 , "On Time",
'FPS selection'[O to C] > 30, "Late")
 
Thank you for your help. 
1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey @dineshj23 ,

 

the following screenshot shows my sample data and also the result:

image.png

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



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

7 REPLIES 7
TomMartens
Super User
Super User

Hey @dineshj23 ,

 

the following screenshot shows my sample data and also the result:

image.png

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



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

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. 

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

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

Hi @dineshj23 ,

 

Try below formula:

Q Timeline = 
var completed = if(isblank([completed date]),today(),[completed date])
var date_diff = datediff([start date],[completed date],day)
return
IF(date_diff>30,"late","on time")

 

Best Regards,

Jay

Hi @Anonymous Thank you for your reply. 

What about the ones that don't have a completed date entered but are already running late? I would call this variable "Pending Late". 

@Anonymous Hi. I think you might ahve not finished writing the complete code. 

Anonymous
Not applicable

Hi @dineshj23 ,

 

--How do I calculate the ones that are running late that don't have the completed date but only the start date. We can use today's date to calculate how late it is. 

if(isblank([completed date]),today(),[completed date])

Below part of formula means:

If the [completed date] is blank, then use today's date in date difference calculation.

If you only want to show "Pending Late" when [completed date] is blank, modify the formula as below:

Q Timeline = 
var a = if(isblank([completed date]),-1,datediff([start date],[completed date],day))
return
IF(a = -1,"pending late",if(date_diff>30,"late","on time"))

 

Best Regards,

Jay

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.

Top Solution Authors