Mar 9, 2010

Dimension Grouping and Ordering in SSAS

Relatively complex example of how to set properties of dimension attributes and hierarchies to get a time dimension that has groupings and sorting.

Scenario

We will use following dimension and hierarchy to demonstrate in this text:

clip_image002

It is based on the following table:

clip_image004

We want to create a complex hierarchy that is ordered using descending order:

clip_image006

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.

Attribute Relationships

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.

clip_image008

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:

clip_image010

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

clip_image012

1 comment:

  1. Thank you very much! Thats exactly what I was looking for! In the past I always used only one Sort instead of multiple instances!

    Works great now!

    ReplyDelete