Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Ragul_1703
Contributor
Contributor

Hi Everyone

How to calculate the business hours in qliksense for service now data using opened date and resolved date.

Labels (3)
1 Solution

Accepted Solutions
priscilarubim
Partner - Creator II
Partner - Creator II

Hi @Ragul_1703!

I've done something similar before, but with days instead of hours. The approach I used was based on a MasterCalendar and I believe the same principle applies here.

The idea is:

1. Create a calendar with hour-level granularity, generating one row per hour between the min and max dates in your dataset, with a flag to identify business hours:

 
If(WeekDay([%DateHourKey]) < 5  // Monday to Friday
   AND Hour([%DateHourKey]) >= 8 
   AND Hour([%DateHourKey]) < 18, 1, 0) as IsBusinessHour

2. Cross your data with this calendar filtering where the hour falls between the opened and resolved dates

3. Count the rows where IsBusinessHour = 1 that gives you the total business hours

No need for IntervalMatch the calendar handles the counting naturally, the same way a day-level calendar counts working days.

Hope this helps! 🙂

View solution in original post

2 Replies
priscilarubim
Partner - Creator II
Partner - Creator II

Hi @Ragul_1703!

I've done something similar before, but with days instead of hours. The approach I used was based on a MasterCalendar and I believe the same principle applies here.

The idea is:

1. Create a calendar with hour-level granularity, generating one row per hour between the min and max dates in your dataset, with a flag to identify business hours:

 
If(WeekDay([%DateHourKey]) < 5  // Monday to Friday
   AND Hour([%DateHourKey]) >= 8 
   AND Hour([%DateHourKey]) < 18, 1, 0) as IsBusinessHour

2. Cross your data with this calendar filtering where the hour falls between the opened and resolved dates

3. Count the rows where IsBusinessHour = 1 that gives you the total business hours

No need for IntervalMatch the calendar handles the counting naturally, the same way a day-level calendar counts working days.

Hope this helps! 🙂

Chanty4u
MVP
MVP

Hi

Try 

This 

LOAD

    *,

    

    (

        // Total elapsed hours

        (resolved_at - opened_at) * 24

        

        // You can then subtract non-business hours

    ) AS TotalHours

 

FROM ...;