Solved

Sort order in MDX returned results

Posted on 2008-06-19
4
1,374 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
srnar earned 500 total points
ID: 21829524
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
ID: 21836182
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
ID: 21841404
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
ID: 22150090
while I do not have what I was looking for - I would like to give points on your effort..

Thanks srnar
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

726 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