MDX for Months across and years down

There was a question recently in the Olap newsgroup at microsoft.public.sqlserver.olap about how to create an MDX query with months across and years going down. Typically the answer to such a question would be to break up the time dimension and put years and months in their own dimensions. By default, and in tools such as Excel this is typically an impossible query. The rules of MDX state that a given dimension cannot participate in more than one axis in a query.


You can create calculated measures (or indeed calculated members in any other dimension) that will give you the effect you are after. Below is an example of some MDX that works against the Foodmart database that will give you the first 6 months across the page and the years going down the page.

Why only the first six months?


a) I'm lazy
b) it is a lot of repetition and 
c) you can get the idea from just the first six months . :)  


Measures.[Jan] as 'sum(filter(descendants(time.currentmember,[time].[month]), ="1"),Measures.[Unit Sales])'
  MEMBER Measures.[Feb] as 'sum(filter(descendants(time.currentmember,[time].[month]), ="2"),Measures.[Unit Sales])'
  MEMBER Measures.[Mar] as 'sum(filter(descendants(time.currentmember,[time].[month]), ="3"),Measures.[Unit Sales])'
  MEMBER Measures.[Apr] as 'sum(filter(descendants(time.currentmember,[time].[month]), ="4"),Measures.[Unit Sales])'
  MEMBER Measures.[May] as 'sum(filter(descendants(time.currentmember,[time].[month]), ="5"),Measures.[Unit Sales])'
  MEMBER Measures.[Jun] as 'sum(filter(descendants(time.currentmember,[time].[month]), ="6"),Measures.[Unit Sales])'

  ,Measures.[Jun] }
.members ON ROWS

Print | posted on Wednesday, September 28, 2005 11:48 AM

Comments on this post

No comments posted yet.

Your comment:

 (will show your gravatar)