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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Gigi_
Frequent Visitor

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

Gigi_
Frequent Visitor

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

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.