Forum Discussion
Anonymous
4 years agoNot applicable
DateDiff between two dates excluding weekends and holidays
I have a holidays table linked to date table and I have 2 calculated columns in the date table: Job to Accep Elapsed TIme Days = (DATEDIFF('FreightForward v2'[JOB_BOOKING_DATETIME],'FreightForwa...
- 4 years ago
Hi Anonymous ,
In order to better check the calculation results, I modify the expression to just calculate the datediff of hours.
You can use TRUNC to truncates a number to an integer by removing the decimal, or fractional, part of the number, like TRUNC( DateDiff_Hour / 24 ).
Working Days (with Calendar Job Booking table) = VAR t1 = CALENDAR ( [JOB_BOOKING_DATETIME], IF ( ISBLANK ( [ACCEPTANCE_DATETIME] ) || [JOB_BOOKING_DATETIME] > [ACCEPTANCE_DATETIME], [JOB_BOOKING_DATETIME], [ACCEPTANCE_DATETIME] ) ) VAR t2 = FILTER ( ADDCOLUMNS ( t1, "IsWorkDay_", LOOKUPVALUE ( 'Calendar Job Booking'[WorkingDay], 'Calendar Job Booking'[Date], [Date] ) ), [IsWorkDay_] = "Yes" ) VAR Days_ = COUNTROWS ( t2 ) - 1 VAR StartWorkingDateTime = MINX ( t2, [Date] ) VAR EndWorkingDateTime = MAXX ( t2, [Date] ) VAR JOB_BOOKING_DATE = DATE ( YEAR ( [JOB_BOOKING_DATETIME] ), MONTH ( [JOB_BOOKING_DATETIME] ), DAY ( [JOB_BOOKING_DATETIME] ) ) VAR ACCEPTANCE_DATE = DATE ( YEAR ( [ACCEPTANCE_DATETIME] ), MONTH ( [ACCEPTANCE_DATETIME] ), DAY ( [ACCEPTANCE_DATETIME] ) ) VAR DateDiff_Start = IF ( StartWorkingDateTime = JOB_BOOKING_DATE, DATEDIFF ( StartWorkingDateTime, [JOB_BOOKING_DATETIME], HOUR ) ) VAR DateDiff_End = IF ( EndWorkingDateTime = ACCEPTANCE_DATE, DATEDIFF ( EndWorkingDateTime, [ACCEPTANCE_DATETIME], HOUR ) ) VAR DateDiff_Hour = IF ( ISBLANK ( [ACCEPTANCE_DATETIME] ) || [JOB_BOOKING_DATETIME] > [ACCEPTANCE_DATETIME], BLANK (), Days_ * 24 - DateDiff_Start + DateDiff_End ) RETURN DateDiff_HourBest Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Jihwan_Kim
4 years agoSuper User
Hi,
Could you share your sample pbix file by sharing the Onedrive link or any other type of link to your sample pbix file?
- Anonymous4 years agoNot applicable
sent you pm with link to file
- Anonymous4 years agoNot applicable
Jihwan_Kim- I understand you're unable to assist but I appreciate your help so far.
VahidDMare you able to assist?