Forum Discussion

prabhatnath's avatar
prabhatnath
Icon for Advocate III rankAdvocate III
2 years ago
Solved

Calculating Days and Hours between 2 DateTime columns excluding Saturday and Sunday

Hello,

I have one Incidents table with columns as below:
IncidentId, Title, Severity, Owner, CreatedDateTime, Status, ResolveDateTime, AcknowledgeDateTime.

The CreatedDateTime, ResolveDateTime, and AcknowledgeDateTime columns are of dateTime data type.

I want help to have:
1) Calculate Age of the Incident in Days based on CreatedDateTime and Current Date Time.
2) Calculate Average Acknowledge time in Days and Hours based on AcknowledgeDateTime and CreatedDateTime
3) Calculate Average Resolve time in Days and Hours based on ResolveDateTime and CreatedDateTime

All above calculattion must be excluding Saturday and Sunday while calculating.

Thanks,
Prabhat
 
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi prabhatnath ,

    Based on my testing, please try the following methods:

    1.Create the sample table.

    2.Create the calculated column to calculate days.

     

    Days = NETWORKDAYS('Table'[CreatedDateTime], TODAY()) - 1

     

    3.Create the calculated column to calculate days and hours based on Acknowledge date and created date.

     

    Acknowledge_aver = 
    VAR days_ = NETWORKDAYS('Table'[CreatedDateTime], 'Table'[AcknowledgeDateTime]) - 1
    VAR hour_ = HOUR('Table'[CreatedDateTime])
    VAR end_hour = HOUR('Table'[AcknowledgeDateTime])
    
    RETURN
    IF(
            days_ > 0,
            (days_ - 1) * 24 + 24 - hour_ + end_hour,
            24-hour_
        )
    
    //COUNTROWS(FILTER(CALENDAR('Table'[CreatedDateTime], 'Table'[AcknowledgeDateTime]), WEEKDAY([Date], 2) < 6))))))

     

    4.Create the calculated column to calculate days and hours based on Resolve date and created date.

     

    Resolve_aver = 
    VAR days_ = NETWORKDAYS('Table'[CreatedDateTime], 'Table'[ResolveDateTime]) - 1
    VAR hour_ = HOUR('Table'[CreatedDateTime])
    VAR end_hour = HOUR('Table'[ResolveDateTime])
    
    RETURN
    IF(
            days_ > 0,
            (days_ - 1) * 24 + 24 - hour_ + end_hour,
            24 - hour_
        )
    

     

    5.Drag the column into the table visual. The result is shown below.

    Best Regards,

    Wisdom Wu

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

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi prabhatnath ,

    Based on my testing, please try the following methods:

    1.Create the sample table.

    2.Create the calculated column to calculate days.

     

    Days = NETWORKDAYS('Table'[CreatedDateTime], TODAY()) - 1

     

    3.Create the calculated column to calculate days and hours based on Acknowledge date and created date.

     

    Acknowledge_aver = 
    VAR days_ = NETWORKDAYS('Table'[CreatedDateTime], 'Table'[AcknowledgeDateTime]) - 1
    VAR hour_ = HOUR('Table'[CreatedDateTime])
    VAR end_hour = HOUR('Table'[AcknowledgeDateTime])
    
    RETURN
    IF(
            days_ > 0,
            (days_ - 1) * 24 + 24 - hour_ + end_hour,
            24-hour_
        )
    
    //COUNTROWS(FILTER(CALENDAR('Table'[CreatedDateTime], 'Table'[AcknowledgeDateTime]), WEEKDAY([Date], 2) < 6))))))

     

    4.Create the calculated column to calculate days and hours based on Resolve date and created date.

     

    Resolve_aver = 
    VAR days_ = NETWORKDAYS('Table'[CreatedDateTime], 'Table'[ResolveDateTime]) - 1
    VAR hour_ = HOUR('Table'[CreatedDateTime])
    VAR end_hour = HOUR('Table'[ResolveDateTime])
    
    RETURN
    IF(
            days_ > 0,
            (days_ - 1) * 24 + 24 - hour_ + end_hour,
            24 - hour_
        )
    

     

    5.Drag the column into the table visual. The result is shown below.

    Best Regards,

    Wisdom Wu

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