MDX Order By not applying to last member in dimension

Post Reply
JohnO
Posts: 96
Joined: Mon Jul 29, 2019 5:02 am
OLAP Product: Planning Analytics
Version: 2.0.9.x
Excel Version: Office 365 16

MDX Order By not applying to last member in dimension

Post by JohnO »

I want to order the N members in my Month dimension by sorting on the 'Seq No' attribute which is a 'N' attribute.

Code: Select all

{
ORDER(
    { TM1FILTERBYLEVEL(
        {TM1SUBSETALL( [Month] )}
        ,0)}
, [}ElementAttributes_Month].[}ElementAttributes_Month].CURRENTMEMBER.PROPERTIES("Seq No"), ASC)
It works fine EXCEPT it does not include the last N member in the dimension regardless of the value of the attribute for that element.

We are using 2.0.9.14, I have a feeling this is something I have come across before.

Comments/ alternatives?
howard40116
Posts: 12
Joined: Tue Oct 02, 2018 5:35 am
OLAP Product: PAL
Version: PAL 2.0.4
Excel Version: excel 2010
Contact:

Re: MDX Order By not applying to last member in dimension

Post by howard40116 »

You can try this MDX query.

Code: Select all


{ORDER(
    {TM1FILTERBYLEVEL(
		{TM1SUBSETALL( [Month] )}
	,0)}
, [Month].[Seq No], ASC)}

burnstripe
Regular Participant
Posts: 197
Joined: Wed May 06, 2020 2:58 pm
OLAP Product: Planning Analytics
Version: 2.0.9
Excel Version: 2016

Re: MDX Order By not applying to last member in dimension

Post by burnstripe »

Alternative option

Code: Select all

{ ORDER( {TM1FILTERBYLEVEL( {TM1SUBSETALL( [Month] )}, 0)}, [}ElementAttributes_Month].( [}ElementAttributes_Month].[Seq No] ), BASC)}
JohnO
Posts: 96
Joined: Mon Jul 29, 2019 5:02 am
OLAP Product: Planning Analytics
Version: 2.0.9.x
Excel Version: Office 365 16

Re: MDX Order By not applying to last member in dimension

Post by JohnO »

burnstripe wrote: Fri Nov 25, 2022 2:22 am Alternative option

Code: Select all

{ ORDER( {TM1FILTERBYLEVEL( {TM1SUBSETALL( [Month] )}, 0)}, [}ElementAttributes_Month].( [}ElementAttributes_Month].[Seq No] ), BASC)}
This one worked! Why?
User avatar
gtonkin
MVP
Posts: 1198
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 Order By not applying to last member in dimension

Post by gtonkin »

Still a bit confused with your original MDX working as you were basing a lookup to }ElementAttributes_Month using members from Month.

Anyway, a few things to consider:
When using ORDER, ASC and BASC are for different cases where BASC breaks down any hierarchies before sorting, ASC sorts within hierarchies.
Attributes are always seen as strings i.e. sorting will be alphabetical 1, 10, 11..28, 29, 3, 30, 31..
Ideally you want to convert the strings to numerics to sort numerically but there is a gotcha where an attribute is blank, you need to trap this and assign a value.

As yet another alternative, you could try this:

Code: Select all

ORDER(
	  {TM1FILTERBYLEVEL({TM1SUBSETALL( [Month].[Month] )},0)},
	  VAL(
		  IIF([Month].[Month].CurrentMember.Properties("Seq No")="",
			"9999" /* Default Value */,
			[Month].[Month].CurrentMember.Properties("Seq No")
		    )
	      )
	), BASC)
JohnO
Posts: 96
Joined: Mon Jul 29, 2019 5:02 am
OLAP Product: Planning Analytics
Version: 2.0.9.x
Excel Version: Office 365 16

Re: MDX Order By not applying to last member in dimension

Post by JohnO »

gtonkin wrote: Fri Nov 25, 2022 6:01 am
Anyway, a few things to consider:
When using ORDER, ASC and BASC are for different cases where BASC breaks down any hierarchies before sorting, ASC sorts within hierarchies.
I was thinking that because the MDX was returning an N level set that the rollup would not be referred to but I am wrong. BASC sorts it.

Thanks
Post Reply