MDX: Sorting on an attribute

Post Reply
User avatar
20 Ton Squirrel
Posts: 71
Joined: Tue Jul 14, 2020 9:53 pm
OLAP Product: TM1
Version: Planning Analytics with Watson
Excel Version: Office 365
Location: Houston, TX

MDX: Sorting on an attribute

Post by 20 Ton Squirrel »

I have a dimension called DSD Month that lists out every month from 1996 to 2030. The element names go like "Mar 1996, Apr 1996, May 1996, …"

There's also an attribute called 'Year-Month' that goes like "1996-03, 1996-04, 1996-05, …"

For a particular subset I just want the end month of each quarter (Mar, Jun, Sep, Dec). I also need it sorted chronologically, of course.

My MDX is as follows:

Code: Select all

ORDER (
      
        UNION ( 
                  UNION (  TM1FILTERBYPATTERN ( TM1FILTERBYLEVEL ( TM1SUBSETALL ( [ DSD Month ] ) , 0 ) , "Mar *" ) 
                         , TM1FILTERBYPATTERN ( TM1FILTERBYLEVEL ( TM1SUBSETALL ( [ DSD Month ] ) , 0 ) , "Jun *" ) )
                , UNION (  TM1FILTERBYPATTERN ( TM1FILTERBYLEVEL ( TM1SUBSETALL ( [ DSD Month ] ) , 0 ) , "Sep *" )
                         , TM1FILTERBYPATTERN ( TM1FILTERBYLEVEL ( TM1SUBSETALL ( [ DSD Month ] ) , 0 ) , "Dec *" ) )
              )
       , [ DSD Month ].[Year-Month]
       , ASC
      )
The MDX works... sorta. I get the proper elements filtered but the sorting is wonky for 1996-1997, everything AFTER 1997 sorts fine.

It goes as follows:
  • Mar 1996
  • Mar 1997
  • Jun 1996
  • Jun 1997
  • Sep 1996
  • Sep 1997
  • Dec 1996
  • Dec 1997
  • Mar 1998
  • Jun 1998
  • Sep 1998
  • Dec 1998
Any ideas on why this would occur? Any thoughts on better means of approaching would be appreciated, also ;)
War teaches us geography, getting old teaches us biology.
User avatar
gtonkin
MVP
Posts: 1261
Joined: Thu May 06, 2010 3:03 pm
OLAP Product: TM1
Version: Latest and greatest
Excel Version: Office 365 64-bit
Location: JHB, South Africa
Contact:

Re: MDX: Sorting on an attribute

Post by gtonkin »

Try change ASC to BASC

Order MDX
"...If BASC or BDESC is specified, the Order function arranges members in the set without regard to the hierarchy...."
BR, George.

Learn something new: MDX Views
User avatar
20 Ton Squirrel
Posts: 71
Joined: Tue Jul 14, 2020 9:53 pm
OLAP Product: TM1
Version: Planning Analytics with Watson
Excel Version: Office 365
Location: Houston, TX

Re: MDX: Sorting on an attribute

Post by 20 Ton Squirrel »

You, good sir, are a gentleman and a genius. An ingenious gentleman.

I should've looked up that function, such a simple solution! It works perfectly now, thanks very much. n__n
War teaches us geography, getting old teaches us biology.
Post Reply