Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1391
  • Last Modified:

Sort order in MDX returned results

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
scrataz
Asked:
scrataz
  • 2
  • 2
1 Solution
 
srnarCommented:
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
 
scratazAuthor Commented:
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
 
srnarCommented:
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
 
scratazAuthor Commented:
while I do not have what I was looking for - I would like to give points on your effort..

Thanks srnar
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now