Forum Discussion
Anonymous
2 years agoNot applicable
DateDiff with time excluding weekends
Hi All,
I have a date table and fact table which are connected to each other via one-to-many.
I'm using the following dax to get the out put:
#Days_Den =
VAR _d = DATEDIFF([ExpectedStartDate], [ExpectedEndDate], SECOND)
VAR _min = DIVIDE(_d,60)
VAR _hour = DIVIDE(_min,60)
VAR _day = DIVIDE(_hour,24)
VAR _weekend = CALCULATE([SumWeekEnds],ALL(Dates),FILTER(Dates,Dates[Date]>=SELECTEDVALUE('Table'[StartDate]) && Dates[Date]<=SELECTEDVALUE('Table'[EndDate])))
return
_day - _weekend
the "_weekend" variable is giving output as 1 day which is ruining the whole output and is unable to get the exact difference as needed.
I'm looking for help calculating the difference between two dates along with time which helps me eliminate weekends with the specified timestamp on the record.
Any help on this would be appreciated!
Regards,
Mahesh
the "_weekend" variable is giving output as 1 day which is ruining the whole output and is unable to get the exact difference as needed.
I'm looking for help calculating the difference between two dates along with time which helps me eliminate weekends with the specified timestamp on the record.
Any help on this would be appreciated!
Regards,
Mahesh
- Anonymous2 years ago
Hi Anonymous ,
Due to I don't know your data model, I will share a workaround by my sample.
Tables:
Date = ADDCOLUMNS(CALENDARAUTO(),"Year",YEAR([Date]),"Month",MONTH([Date]),"WeekDay",WEEKDAY([Date],2))Measure:
#Days_Den = VAR _d = DATEDIFF(MAX('Table'[ExpectedStartDate]), MAX('Table'[ExpectedEndDate]), SECOND) VAR _min = DIVIDE(_d,60) VAR _hour = DIVIDE(_min,60) VAR _day = DIVIDE(_hour,24) VAR _weekend = CALCULATE(COUNT('Date'[Date]),FILTER('Date','Date'[WeekDay] in {6,7} && 'Date'[Date]>=MAX('Table'[ExpectedStartDate]) && 'Date'[Date]<= MAX('Table'[ExpectedEndDate]))) return _day - _weekendResult is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
1 Reply
- AnonymousNot applicable
Hi Anonymous ,
Due to I don't know your data model, I will share a workaround by my sample.
Tables:
Date = ADDCOLUMNS(CALENDARAUTO(),"Year",YEAR([Date]),"Month",MONTH([Date]),"WeekDay",WEEKDAY([Date],2))Measure:
#Days_Den = VAR _d = DATEDIFF(MAX('Table'[ExpectedStartDate]), MAX('Table'[ExpectedEndDate]), SECOND) VAR _min = DIVIDE(_d,60) VAR _hour = DIVIDE(_min,60) VAR _day = DIVIDE(_hour,24) VAR _weekend = CALCULATE(COUNT('Date'[Date]),FILTER('Date','Date'[WeekDay] in {6,7} && 'Date'[Date]>=MAX('Table'[ExpectedStartDate]) && 'Date'[Date]<= MAX('Table'[ExpectedEndDate]))) return _day - _weekendResult is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.