How to order a list of dimension members - Adventure Works 2008 Date dimension

Say I had this query against the AW 2008 data cube.

 SELECT NULL ON COLUMNS, STRTOMEMBER('[Date].[Fiscal].[Month].&[' + CSTR(YEAR(NOW()) - 10) + ']&[7]') :
 STRTOMEMBER('[Date].[Fiscal].[Month].&[' + CSTR(YEAR(NOW()) + 1) + ']&[12]')
 ON ROWS
 FROM [Adventure Works];

How can I sort it in decending order, where the more recent date is at the top ?

September 11th, 2015 12:32pm

Hi shiftbit, 

In Analysis Services, when applying dimension members on rows in MDX query, no matter the how you write the date range, it will order the dimenson members based on the OrderBy Prpoerty of the attribute you set in dimension. However, we can use Order() function to get the expected order. In this scenario, if you want to sort the date members in desc order. You need to create a measure to return the member_key, then use this calculated measure as numeric expression in Order() function.

with member [x] as
[Date].[Calendar].currentmember.member_key
select {} on 0,
order({[Date].[Calendar].[Date].&[20050713]: [Date].[Calendar].[Date].&[20050724]},[x],desc)on 1
from
[Adventure Works]

Reference:
Order (MDX)

Regards,

Free Windows Admin Tool Kit Click here and download it now
September 13th, 2015 12:07pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics