Relatively complex example of how to set properties of dimension attributes and hierarchies to get a time dimension that has groupings and sorting.
We will use following dimension and hierarchy to demonstrate in this text:
It is based on the following table:
We want to create a complex hierarchy that is ordered using descending order:
Sorting sequence will be used to define order of members.
Ordering by Attribute
You probably know that an attribute in SSAS dimension can be sorted by Key and Name. That is controlled using OrderBy property of the attribute.
You can also sort it using another attribute. You fist have to specify the attribute using OrderByAttribute property and then to specify in OrderBy to be sorted by AttributeKey or AttributeName.
For sorting attribute to appear in the OrderByAttribute list, it must have attribute relationship with the attribute.
The following picture shows how you can set attribute relationships between attributes in a hierarchy. This can be used in both SQL Server 2005 and 2008.
Most people have a trouble to visualize relationships between attributes. Should Month Alias be under Quarter or Quarter under Month Alias? The way I remember this is to say to myself sentence about aggregating. Something like Months aggregate (or roll up or are part) of Quarter. And Quarters are part of Year.
In SQL Server 2008 there is now a new interface that is easier to use. It will visuale manage relation like:
Month ----> Quarter ------> Year
To be able to use sorting attribute it needs to be included in attribute relationship. The following picture shows one way to do this:
Sort Seq will take place in relationship between Moth and Quarter
Month ----> Sort Seq ----> Quarter ------> Year
Combining Grouping & Sorting
Since Quarters and Years also have to be sorted in Descending order, you could use two more instances of Sort Seq attribute to order them. Just include them in attribute relationship:
Month ----> Sort Seq ----> Quarter ------> Sort Seq 1 ----> Year ----> Sort Seq 2