Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

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([ExpectedSta...
  • Anonymous's avatar
    Anonymous
    2 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 - _weekend

    Result is as below.

     

    Best Regards,
    Rico Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.