Solved

Sort order in MDX returned results

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

728 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