One option is: using UDF (User-Defined Function). Check out this document "How To Create User-Defined Functions".
First you need to create a function in your database to return the number of weekdays only. Then follow the instructions in the above document to make the database function visible for selection in Impromptu.
The general logic to calculate the number of weekdays without including Sat and Sun in a database function is: Keep adding 1 day from StartDate until StartDate is Sun and keep subtracting 1 day to EndDate until Endate is Sat. Then multiply DateDiff(week,StartDate,EndDate) by 5 to get the number of weekdays, then add it to the number of weekdays found while doing adding and subtracting above. REMEMBER to add logics to check first hand how many days apart the orginal StartDate and EndDate are before doing the adding and subtracting and deal with each case accordingly.
Your DBA might already have such a similar function.
SELECT SUM(days) "Total Working Days"
FROM (SELECT ((TO_DATE('11-APR-07') + TRUNC((TO_DATE('13-APR-07') - TO_DATE('11-APR-07') + 1)/7)*7 -
1) - TO_DATE('11-APR-07') + 1)*5/7 days
FROM DUAL
UNION ALL
SELECT CASE
WHEN TO_CHAR((TO_DATE('11-APR-07') + TRUNC((TO_DATE('13-APR-07') -
TO_DATE('11-APR-07') + 1)/7)*7 - 1)+ROWNUM, 'D')
NOT IN (1, 7)
THEN 1
ELSE 0
END
FROM (SELECT 'x'
FROM DUAL
GROUP BY CUBE (1,2,3)
)
WHERE (TO_DATE('11-APR-07') + TRUNC((TO_DATE('13-APR-07') - TO_DATE('11-APR-07') + 1)/7)*7 -
1) + ROWNUM <= TO_DATE('13-APR-07')
)
SELECT SUM(days) "Total Working Days"
FROM (SELECT ((TO_DATE('11-APR-07') + TRUNC((TO_DATE('13-APR-07') - TO_DATE('11-APR-07') + 1)/7)*7 -
1) - TO_DATE('11-APR-07') + 1)*5/7 days
FROM DUAL
UNION ALL
SELECT CASE
WHEN TO_CHAR((TO_DATE('11-APR-07') + TRUNC((TO_DATE('13-APR-07') -
TO_DATE('11-APR-07') + 1)/7)*7 - 1)+ROWNUM, 'D')
NOT IN (1, 7)
THEN 1
ELSE 0
END
FROM (SELECT 'x'
FROM DUAL
GROUP BY CUBE (1,2,3)
)
WHERE (TO_DATE('11-APR-07') + TRUNC((TO_DATE('13-APR-07') - TO_DATE('11-APR-07') + 1)/7)*7 -
1) + ROWNUM <= TO_DATE('13-APR-07')
)
The other way to do this is to have a table of dates (like a date dimension table) and have a flag column to indicate whether the day is a workday or not, something like:
cal_date dow_name is_work_day
--------- ------------- ------------
1/01/2008 Tuesday N
2/01/2008 Wednesday Y
3/01/2008 Thursday Y
4/01/2008 Friday Y
5/01/2008 Saturday N
6/01/2008 Sunday N
7/01/2008 Monday Y
8/01/2008 Tuesday Y
9/01/2008 Wednesday Y
10/01/2008 Thursday Y
11/01/2008 Friday Y
12/01/2008 Saturday N
13/01/2008 Sunday N
14/01/2008 Monday Y
15/01/2008 Tuesday Y
Note that Jan 1, while a Tuesday, is not a work day - it's a public holiday. Programatic solutions can be complicated and usually can't deal with situations like Easter / Passover / Diwali that don't fall on set dates, a table can. What's more the table only needs to be created once and requires minimal maintenance. If you've got a data warehouse you'll already have a date dimension. Other columns can be used to support other date related features such as accounting calendars.
Impromptu is a reporting tool so I'd be recommending a date table in the reporting database to your DBA if you don't already have one.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.