If you have requirement to present your data based on the fiscal year user is using, you can provide user with option to either select fiscal year he wants or can make it dynamic in the report such that it dynamically select the current user location and render the report.
This is one way to model your time dimension to support multiple fiscal year. There are obviously other ways to support various fiscal year like by adding more columns to time dimensions, storing into separate fact for each single fiscal year you may need to support, building separate hierarchies for each fiscal year etc. I insist the approach because you don’t have to add columns in the database time dimension table to support and of course it is not considered good to add columns to support piece of business. We should always try and see if it can be done using same table columns.
We will create 3 tables. Find script below to create these tables. We will create a calendar dimension table with all the attributes, a Date dimension table with key and date and a bridge table to connect these two dimension tables (Calendar and Date).
Here is the script to create 3 tables -
//Calendar dimension table |
Let’s setup data source view in the OLAP. Add above 3 tables in the DSV, you should get this -
Next populate above tables using SQL script. Make sure you have entries for each single day in this table. You need to have entries per Gregorian calendar and same number of entries for each month of a year starting February (and of course for each year) . Reason, we are not creating entries for January because if fiscal starts from January it will be same as calendar year.
Here is the sample script to populate above tables.
At this point if I assume you have just populated one year entries into the calendar dimension this is how number of entries should be in the calendar dimension table -
Add calendar and set dimension properties as under -
Set additional calendar attribute properties as under -
Next build hierarchy and set attribute relationship as under -
Add Date dimension and leave everything to default value. I however changed the key column to Date from Date_Key. Here is the snap of the Date dimension -
Now we will add a fact table (actual fact) for sales. Fact table will be linked to calendar and date dimensions.
CREATE TABLE [DBO].[TTB_FACT_SALES]( |
Add above fact table to data source view and it should look like this at this point -
Create a measure from the bridge table. This will act as intermediate fact table when we join with sales fact through calendar dimension (using many to many relationship and will be discussed later). It is nothing but the fact less fact table and we will not be using this for anything. Let’s add count measure on Date_key column. Here is what I mean -
Populate sales fact table as under. I just created for all the possible date and calendar key combination for us to be able to test with some data.
INSERT INTO [DBO].[TTB_FACT_SALES]([DATE_KEY], [CALENDAR_KEY], [SALES_AMOUNT]) |
Next add sales measure to the cube and leave everything else to default. This is how cube structure should look like.
Set the dimension usage tab as under. Link DATE CALENDAR measure group with Calendar and Date dimension using Regular relationship type. This measure group we will be using when linking with actual fact which is sales in this case.
Link sales fact with Date dimension using Regular relationship type and with calendar dimension using many to many relationship type through bridge table measure group (above one). Find below dimension usage tab and many to many relationship snap for your to connect well.
Process the cube and analyze what we got in here. Drag sales in the measure area and calendar hierarchy. This is what we get, all the values are same for the Calendar name because we had set IsAggregatable = False.
What we gonna see next is interesting. In Gregorian calendar March falls in Q1 and in March based fiscal again it will fall in Q1 but in April based fiscal April will fall in Q1. Similarly in Gregorian calendar May falls in Q2 but in April based fiscal it will fall in Q1 etc. So what I am driving here is, sales value will be accrued to different quarter in a year based on what is the starting month of a fiscal.
Rest you browse the cube and check the sales value distribution. Hope this will help you design time dimension when you have to support different calendar, fiscal etc. Thank you and bye for now!
No comments:
Post a Comment