I have a date dimension table where i need to add NumberofBusinessDay column which will tell me the number of business day it is. For example:
Date WeekendFlag BusinessDayFlag **NumberofBusinessDay**
01/01/2015 N N 0
01/02/2015 N Y 1
01/03/2015 Y N 2
01/04/2015 Y N 2
01/05/2015 N Y 2
I have assigned the number of business days to the weekdays but I am struggling with assigning a number to a weekend day which will be the same as following business day - Monday (in case Monday is a holiday, it will be Tuesday), as shown in above table. Here it what I have so far:
Date WeekendFlag BusinessDayFlag **NumberofBusinessDay**
01/01/2015 N N 0
01/02/2015 N Y 1
01/03/2015 Y N NULL
01/04/2015 Y N NULL
01/05/2015 N Y 2
Any kind of help would be appreciated
My query for assigning BusinessDays for weekdays (only 2015 data):
SELECT Date, WeekendFlag, BusinessDayFlag
,NumberofBusinessDay = CASE WHEN WeekendFlag = 'N' THEN
ROW_NUMBER() OVER (Partition BY YearCode, MonthCode ORDER BY WeekendFlag, Date ASC)
END
INTO #test
FROM DimDate
WHERE Date between '01/01/2015' AND '12/31/2015' --for testing purposes only
ORDER BY Date ASC
Just an FYI - purpose for accounting weekends as business days is because we don't want to miss any activities that happens during weekend (its a possibility) and we want to count those actitivies in the next business day.
check with below sql
you can update any date as businessday or weekend day and calculate NumberofBusinessDay from NumberofBusinessDay calculation code part . i marked only saturaday as weekend day and populated table
Thanks