Solved

Sort order in MDX returned results

Posted on 2008-06-19
4
1,364 Views
Last Modified: 2013-11-16
Hi Experts,

I have this question regarding the sort order of MDX query. I did the example (attached doc) on AdventureWorks cube.

Question:
1.      Does anyone know what is the sort order for the dataset returned by the Descendants clause?
I need to use Descendants clause (ALL level) so that I can get the totals in my report. Since my matrix has all non-key attributes on the dynamic row area, I dont get the totals if I use the default Visual studio generated query (  example:  NON EMPTY { ([Reseller].[Business Type].[Business Type].ALLMEMBERS
        * [Reseller].[Address].[Address].ALLMEMBERS  (Key element is the use of ALLMEMBERS)
).

 If I use the Descendants in my query, my sort order is messed up.

         DESCENDANTS([Reseller].[Business Type].[All Resellers] ,,SELF_BEFORE_AFTER)
|               *  DESCENDANTS([Reseller].[Address].[All Resellers] ,,SELF_BEFORE_AFTER)

I cannot use the RS sorting element.

Question can be phrased like this as well: If I have only non-key attributes in the matrix dynamic area and I use the Descendants clause for my MDX (to get the totals) with no RS Sorting element in RDL, what governs the sort order in the report?

If you can provide some direction or hint, I will still award ful points.

Thanks,
Scrataz
MDX-Query.doc
0
Comment
Question by:scrataz
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
srnar earned 500 total points
Comment Utility
crataz, I run MDX (see script 1) in Management Studio and they gave me correct sort order e.i 2251 before 6405 (although descendants is getting data in dimension tree). Do you have Service Pack 2?

Also note that you are using a Measure that it is not used with Reseller dimension. You have to use [Reseller Order Count] measure. Also replace NON EMPTY with NONEPMTYCROSSJOIN - it gives data more quickly.

You can also try to use MDX ORDER function - see last script - it has option to ignore dimension structure (BASC/BDESC where B = break).
--Script1 - used NONEMPTYCROSSJOIN

SELECT NON EMPTY { [Measures].[Reseller Order Count] } ON COLUMNS,

NONEMPTYCROSSJOIN(

	DESCENDANTS([Reseller].[Business Type].[All Resellers] ,,SELF_BEFORE_AFTER)

	,

	DESCENDANTS([Reseller].[Address].[All Resellers] ,,SELF_BEFORE_AFTER)

	,

	DESCENDANTS([Reseller].[Number of Employees].[All Resellers] ,,SELF_BEFORE_AFTER)

	,

	DESCENDANTS([Reseller].[Reseller].[All Resellers] ,,SELF_BEFORE_AFTER)

	,

	[Measures].[Reseller Order Count]

	,

	4

	)

	ON ROWS

FROM [Adventure Works]
 
 

--LastScript - ORDER FUNCTION

with set Sorted

as

	ORDER({DESCENDANTS([Reseller].[Reseller Type].[All Resellers] ,,SELF_BEFORE_AFTER)}, [Measures].[Reseller Order Count], BDESC)

SELECT NON EMPTY { [Measures].[Reseller Order Count]} ON COLUMNS,

	Sorted

	ON ROWS

FROM [Adventure Works]

Open in new window

0
 

Author Comment

by:scrataz
Comment Utility
Thanks srnar.

I've SP2. Not sure about management studio but if you create a report project in VS, they are not ordered (Well, to be precise, VStudio puts RDL <Sorting> tab automatically, you'd have to tkae that off to see the order returned by the descendants function in MDX)

I've other ways to make it in sort as well, I was just curious to know what is the actual order of data returned by the Descendants clause? (I've tried it on many reports and it seems to be random).

Also, why can't I use Order count from Sales dimension? What association does Reseller dimension has with Reseller Order Count in the cube?

Thanks

0
 
LVL 8

Expert Comment

by:srnar
Comment Utility
Open Adventure solution and there you can see that the Reseller dimension is not used in Sales measure group. Also look at the numbers (Sales Order Count) on your report - they are still the same (repeating).

Descendants function should return data in order that is set on the level/attribute that is used in function (OrderBy KeyColumn/NameColumn etc. proberty on attribute).

There is something rotten on your analysis database - can you try other server/database?
0
 

Author Comment

by:scrataz
Comment Utility
while I do not have what I was looking for - I would like to give points on your effort..

Thanks srnar
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now