Solved

Sort order in MDX returned results

Posted on 2008-06-19
4
1,367 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
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Restrict result set 1 39
View SQL 2005 Job package 16 43
Need help how to find where my error is in UFD 6 30
Whats wrong in this query - Select * from tableA,tableA 11 31
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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…

809 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