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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

DATEDIFF() not giving the right results

Hi, 
I'm having trouble writing a measure.

 

I have two tables:

- One that tells me when a design process is due (named

"Date Initiale (Demandée com)") and the actual date it has been delivered at (named "Task Completion date").

- The other one, is my Calendar that has two boolean columns that tell me wether a given day is a weekend (named "Jours OFF") or holiday (named "Non travaillé"). With 1 if it is and 0, if not.

I want to figure out how long my design processes have been late (due date is passed but task completion date for the given process is after the due date or is still empty). So the logic I followed is:

- If a design process has been delivered late, I use it's task completion date for the calculation.

- If it's still ongoing (meaninng no task completion exist) I'll use today as the end date for the calculation. 

- Then I use DateDiff to identify the difference in days between the due date and the end date. To that result, I remove all weekends and holidays that may be included in that frame to only count working days. 

 

The problem is, the results aren't correct at all and it seems DateDiff might be the reason. Though, I'm not sure why it's the case. 

 

For example here's a table with the results of my measure for all ongoing late process (delay(days)) with their due dates. As they all don't have a completion date, I'm using Today as end date to make my calculations:

Design process codeDelay(days)YearMonthDay
XXXXXXXX232024Oct4
YYYYYYYY122024Sept20
ZZZZZZZZ122024Oct18
VVVVVVV112024Oct7
WWWWW32024Oct31
TTTTTTTTT22024Nov4

 

The process T shouldn't be 2 days late but 3 since we're November 7th and the process X shouldn't be only 20 days from September to today as November 1st was the sole holiday during that period.


Here is the measure:

 

 

 

Retard par Notification = 

VAR DateInitiale = MAX( 'Tasks details'[Date Initiale (Demandée com)])
VAR TaskCompletionDate = MAX( 'Tasks details'[Task Completion date])

VAR DateActuelle = MAX('_Calendrier'[Date])
VAR DateFin = IF(NOT(ISBLANK(TaskCompletionDate)), TaskCompletionDate, DateActuelle)

-- here is to manage the holidays and weekends 
VAR JoursOff = 
    CALCULATE(
        COUNT('_Calendrier'[Date]),
        '_Calendrier'[Date] >= DateInitiale && 
        '_Calendrier'[Date] <= DateFin &&
        ('_Calendrier'[Jours OFF] = 1 || '_Calendrier'[Non travaillé] = 1)
    )

VAR RetardNet = DATEDIFF(DateInitiale, DateFin, DAY) +1 - JoursOff 

RETURN 
    IF(RetardNet > 0, RetardNet, BLANK())

 

 

 

  

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Try using TODAY() for DateActuelle

View solution in original post

2 REPLIES 2
johnt75
Super User
Super User

Try using TODAY() for DateActuelle

Anonymous
Not applicable

I did just that and it works now. Thank you!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.