Hopefully you are continuing from part one of this post.
If you have run the script to create and populate your date, calendar and bridge tables you can go ahead and add the tables to your Analysis Services project’s data source view. The tables all have foreign keys so just add them and the DSV will sort out the relationships.
Next, create two dimensions – one based on the date dimension and one based on the calendar dimension. Set the Type of the calendar dimension to ‘Time’ and the ErrorConfiguration to ‘Default’. On the calendar dimension create these attributes with the associated properties:
- Calendar Key
Name: ‘Date’
Type: Calendar –> Date
NameColumn: ActualDate - Calendar Name
DefaultMember: [Calendar].[Calendar Name].&[1]
IsAggregatable: False
KeyColumns: CalendarOrder - Date Name
Type: Calendar –> Date - Year
Type: Calendar –> Years
NameColumn: YearName - Quarter
Type: Calendar –> Quarters
KeyColumns –> Quarter and Year
NameColumn: QuarterName - Month
Type: Calendar –> Months
KeyColumns –> Month, Quarter and Year
NameColumn: MonthName
You might well want to use some of the other columns in the calendar table such as month of year. My date dimensions are usually very rich so fill your boots and add whatever you think will help your end users.
Next, create a hierarchy of Calendar Name –> Year –> Quarter –> Month –> Date and set up the attribute relationships.
At this point you should be able to process the dimension. You can then browse it to get something like this:
As you can see, the definition of what constitutes ‘2008’ differs based on the calendar you expand.
Bridging the Many-to-Many
Create a new measure group in your cube using the bridge table as its source. A count measure will be added automatically. This is required but useless so set its Visible property to False.
On the Dimension Usage tab, make sure the new measure group is connected to the Date and Calendar dimensions (the relationships in the DSV will do this properly when you add the dimensions to this tab).
Any measure groups that need to join to the calendar dimension must have a regular join to the date dimension and a many-to-many join to the calendar dimension through the bridging table measure group.
You can now process and test the cube.
Here is an example with a very simple sales measure group, showing two calendars being browsed:
The TOTAL and all the total for each months for each calendar is the same – 75. This is because the calendar name attribute is set to non-aggregatable. But the months belong in different quarters. For example, April is in Q2 in the Gregorian calendar, but it is the first month of Q1 in a fiscal calendar which starts April 1.
You can also use the calendar name as a parameter in a Reporting Services report based on the cube – just make sure the parameter is set to allow single values only.
What if you also create reports from the relational database? You now have to join to two extra tables every time you want to include a date, don’t you? Well, no, you don’t, and I will explain why in my next post.
