Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Create and Populate Date Dimension for Data Warehouse

Recently I have been working on new data warehouse project using SSAS and SSIS. And I
had to populate the Date dimension table, with granularity at individual day with various
other values like Day of Month, Day of Week, Day Of Quarter, Day Name, Day of Week, Day
of Week in month, First Day of Month, First Day of Quarter etc.

Quickly I did search internet but could not find the script which reasonably satisfy my
requirement. So I have decided write my script as listed below.

This script will populate Date dimension for required as per UK dates like Holidays, Monday
week start day etc. If you need to populate it for USA or other country then you have to
change few things like Holiday Listing, FullDate, Week Start Day etc.

I found one issue while running this script while running on different server. This was
related to First Day of Week. You can check first day of week using @@DATEFIRST. If it
returns 1 then this script will work fine, but if it is other then 1 then you have to change the
script calculation. To get away with this problem I have statement at beginning of this script
to set first day of week to 1 using SET DATEFIRST 1.

This scripts populated below fields for Date dimension table.


DateKey -- Integer date key is created as YYYYMMDD
[Date] -- Actual date value

Day Of Month -- Day number of month


Day Of Month With Suffix -- Apply suffix as 1st, 2nd ,3rd etc

Day Of Quarter -- Day number of quarter


Day Of Quarter With Suffix -- Apply suffix as 1st, 2nd ,3rd etc
Month Of Quarter -- Month number of quarter

Day Name -- Name of the day, Sunday, Monday


Day Of Week In Month --1st Monday, 2nd Monday etc in Month
Week Of Month -- Week Number of Month
Week Of Quarter -- Week Number of the Quarter
Month Name -- January, February etc
Month Year -- Jan-2014, Feb-2014 etc
MMYYYY
First Day Of Month -- Date for first day of month
Last Day Of Month -- Date for last day of month
First Day Of Quarter -- Date for first day of quarter
Last Day Of Quarter -- Date for last day of quarter

Full Date -- Date in dd-MM-yyyy format


Day Of Week -- First Day Monday=1 and Sunday=7

Day Of Calender Year -- Day number in calender year


Week Of Calender Year -- Week Number of the calender Year
Calender Month -- Number of the Month 1 to 12
Calender Quarter -- Calender quarter number Jan-Mar = 1, Apr-Jun=2, Jul-Sep = 3 and
Oct-Dec = 4
Calender Year -- Year value of Date stored as YYYY
Day Of Financial Year -- Day number in financial year
Week Of Financial Year -- Week Number of the financial Year
Financial Month -- Month number in financial year being Apr=1 and Mar=12
Financial Quarter -- Calender quarter number Apr-Jun = 1, Jul-Sep = 2, Oct-Dec = 3 and
Jan-Mar = 4
FinancialYear -- Year value of Date stored as YYYY/YYYY

IsWeekday -- 0=Week End ,1=Week Day


IsHoliday -- Flag 1=National Holiday, 0=No National Holiday
HolidayName -- Name of Holiday in UK

Please find the compete script as below. Please let me know if you need any help or if you
feel I have done something wrong in this script.

You might also like