If you need to calculate it on the fly and are using an Oracle back end, you can use a combination of the Lag function and your calendar table to do it. You will need to decide if you include holidays or not. If you wish to exclude them the SQL gets a bit more complex and you have to have them marked in your calendar table.
I knocked together this function a while ago for transact to do just what you are after;
CREATE FUNCTION dbo.workdays_between(@from_date DATETIME, @to_date DATETIME)
RETURNS DECIMAL(9,0)
AS
BEGIN
DECLARE @v_days INTEGER,
@progress_date DATETIME,
@start_date DATETIME,
@end_date DATETIME
/*Check which day comes first*/
IF @from_date > @end_date
BEGIN
SET @start_date = @to_date
SET @end_date = @from_date
END
ELSE
BEGIN
SET @start_date = @from_date
SET @end_date = @to_date
END
SET @v_days = 0
SET @progress_date = @start_date
/*loop from first days to last, if days is weekday add one else add zero*/
WHILE @progress_date <= @end_date
BEGIN
SET @v_days = @v_days + (SELECT CASE DATEPART(WEEKDAY,@progress_date)
WHEN 1 THEN 0
WHEN 7 THEN 0
ELSE 1
END)
SELECT @progress_date = DATEADD(dd,1,@progress_date)
END
RETURN @v_days
END
It is inclusive and does not take account of corporate holidays (that would require a calendar table.
Shouldn’t be to difficult to convert for oracle (use a cursor rather than the select case that Ihave used).
If you use Oracle and you can consider only fixed holidays (sat & sun)
yes you can use the DayOfWeek function
and then make a measure object not including sat & sun
it is the same way of the script but it is directly from BO
thanks for all your advice, I dont have much access for making changes to the actual database so I tried to use the “Date Functions” - mainly using the ‘W eek’ and ‘DayNumberOfWeek’ functions.
I calculated the DayNumber for each of the two dates (e.g. 1 for monday, 2 for tues etc) and the week number for each of the two dates.
From that I obtained the week diff (the number of whole weeks between the two dates)
After a bit of trial and error (!) I then applied the following formula to calculate the number of business days elapsed:
=(<day number (engine date)>-<Day number (trade date)>)+((*5)+1)
I tested my results in excel with NetWorkDays function and it seemed to work fine…
Of course this currently only works as long as the two dates are in the same year (which mine greatfully are) but I think the formula could be amended to take years into account quite easily…
It doesn’t take into account bank holidays but Im happy to live with that one!!
Has anyone tried using a business calendar table in oracle to calculate between two dates? and apply an object that calculates only business days in the universe level?
Thanks for your reply, Do you have any sample approach as to how can you make a business day lookup for objects of the universe. I have created a physical table in oracle but still figuring out my approach on getting business days between2 dates at universe level…