Forum Discussion

MSuser5's avatar
MSuser5
Icon for Helper III rankHelper III
4 years ago
Solved

calculate SLA between start - end dates except weekends,holidays

Hi Folks, i have two dates with time (start date , end date) need to calculate how long it tooks complete the activity except weekends and holidays in calender table working day, holiday column is a...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi MSuser5 ,

    I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can create a calculated column as below:

     

    Activity took = 
    VAR _sdate =
        DATE ( YEAR ( 'Table 1'[start date] ), MONTH ( 'Table 1'[start date] ), DAY ( 'Table 1'[start date] ) )
    VAR _edate =
        DATE ( YEAR ( 'Table 1'[end date] ), MONTH ( 'Table 1'[end date] ), DAY ( 'Table 1'[end date] ) )
    VAR _sstart =
        DATEVALUE ( ( _sdate + 1 ) & " " & TIME ( 0, 0, 0 ) )
    VAR _eend =
        DATEVALUE ( ( _edate ) & " " & TIME ( 0, 0, 0 ) )
    VAR _wehdates =
        CALCULATETABLE (
            VALUES ( 'calender'[Date] ),
            FILTER (
                'calender',
                'calender'[IS_Workingday] = "Weekend"
                    || 'calender'[IS_Holiday] = "Holiday"
            )
        )
    VAR _s1duration =
        IF (
            _sdate IN _wehdates,
            0,
            DATEDIFF ( 'Table 1'[start date], _sstart, SECOND )
        )
    VAR _e1duration =
        IF (
            _edate IN _wehdates,
            0,
            DATEDIFF ( _eend, 'Table 1'[end date], SECOND )
        )
    VAR _duration =
        IF (
            _sdate = _edate,
            DATEDIFF ( 'Table 1'[start date], 'Table 1'[end date], SECOND ),
            _s1duration + _e1duration
        )
    VAR _minutes =
        INT ( _duration / 60 )
    VAR _RemainingSeconds =
        MOD ( _duration, 60 )
    VAR _hours =
        INT ( _minutes / 60 )
    VAR _RemainingMinutes =
        MOD ( _minutes, 60 )
    VAR _days =
        INT ( _hours / 24 )
    VAR _RemainingHours =
        MOD ( _hours, 24 )
    VAR _bdates =
        CALCULATE (
            DISTINCTCOUNT ( 'calender'[Date] ),
            FILTER (
                'calender',
                'calender'[IS_Workingday] = "Working day"
                    && 'calender'[IS_Holiday] = "Working day"
                    && 'calender'[Date] > _sstart
                    && 'calender'[Date] < _eend
            )
        )
    RETURN 
        IF ( _sdate = _edate, 0, ( _bdates + _days ) ) & " Day(s) " & _RemainingHours & " hr(s) " & _RemainingMinutes & " min(s) " & _RemainingSeconds & " sec(s)"

     

    Best Regards