3

I've run into some confusing behavior in Analysis Services 2005 (and 2008 R2) and would appreciate it if someone could explain why this is happening. For the sake of this question, I've reproduced the behavior against the Adventure Works cube.

Given this MDX:

SELECT [Customer].[Education].[(All)].ALLMEMBERS ON COLUMNS,
    Order(DrillDownLevel({[Customer].[Customer Geography].[All Customers]}), 
          ([Measures].[Internet Order Count]), 
          ASC) ON ROWS
FROM (SELECT {[Customer].[Education].&[Partial High School]} ON COLUMNS FROM [Adventure Works])
WHERE [Measures].[Internet Order Count];


The query evaluates with the ordered set on rows:
All Customers: 2, 136
Germany: 269
France: 298
Canada: 304
United Kingdom: 311
United States: 457
Australia: 497

However, if I include the All Member (or defaultmember) for Education in the tuple used in the order statement:

SELECT [Customer].[Education].[(All)].ALLMEMBERS ON COLUMNS,
        Order(DrillDownLevel({[Customer].[Customer Geography].[All Customers]}), 
              ([Measures].[Internet Order Count], [Customer].[Education].[All Customers]), 
              ASC) ON ROWS
FROM (SELECT {[Customer].[Education].&[Partial High School]} ON COLUMNS FROM [Adventure Works])
WHERE [Measures].[Internet Order Count];


Then the the set comes back in a significantly different order:
All Customers: 2, 136
France: 298
Germany: 269
United Kingdom: 311
Canada: 304
Australia: 497
United States: 459

Note that France and Germany are out of order relative to each other. Same with Canada / UK and with USA / Australia. From what I can tell, it's ordering based on the aggregation before the sub-cube is evaluated.

Why does including this member (which should implicitly be in the tuple in the first example?) cause the evaluation of the order statement to look outside of the subcube's visual totals? Filter and TopCount etc functions seem to have the same behavior.

Cheers.

3 Answers 3

2

My guess is that since the 2 attributes are related only by key (no direct relationship exists) the resulting crossjoin of the attributes results on the key members being aggregated and this is where the visualtotals is not applied (it's one of the ways how to calculate tho nonvisualtotal with subselects).

I've constructed a query to demonstrate what is happening as a result of that crossjoin:

WITH

MEMBER sortExpr as
AGGREGATE(Descendants([Customer].[Customer Geography].CurrentMember), [Measures].[Internet Order Count])

SELECT 
[Customer].[Education].[(All)].ALLMEMBERS 
*
{[Measures].[Internet Order Count], sortExpr} ON COLUMNS,
Order
(
    DrillDownLevel({[Customer].[Customer Geography].[All Customers]})
    ,sortExpr
    ,ASC
) ON ROWS
FROM 
(
    SELECT 
    {[Customer].[Education].&[Partial High School]} ON COLUMNS 
    FROM [Adventure Works]
)
;

EDIT: Here is another query that shows that the expression works correctly with attribute overwrites once you solve the subselect problem using a query scoped set (well-known solution):

WITH

set sub as
[Customer].[Customer Geography].[Customer]

MEMBER sortExpr2 as
Aggregate(existing sub, [Measures].[Internet Order Count])

SELECT 
[Customer].[Education].[(All)].ALLMEMBERS 
*
{[Measures].[Internet Order Count], sortExpr2} ON COLUMNS,
Order
(
    DrillDownLevel({[Customer].[Customer Geography].[All Customers]})
    ,
    (
--      [Customer].[Customer Geography].CurrentMember,
        [Customer].[Education].[All Customers],
        sortExpr2
    )
    ,ASC
) ON ROWS
FROM 
(
    SELECT 
    {[Customer].[Education].&[Partial High School]} ON COLUMNS 
    FROM [Adventure Works]
)
;

Thanks to Boyan for tweeting this question. Regards, Hrvoje

1
  • Heh, well, you are tackling a completely different issue here. Not only your expressions are not equivalent to those in the questions, but they also obscure the logic. Why are they not equivalent - in both cases you are introducing member expressions in different elements, which are evaluated differently. In the first case, you are adding a calculated member with .CurrentMember, which does not get affected by the subselect. In the second case, you are also introducing a named set, which has its own perks in this regard. However, thanks for adding your thoughts, Hrvoje. Jul 5, 2011 at 5:26
1

Note: Have a look at http://www.bp-msbi.com/2011/07/mdx-subselects-some-insight/ where I explained the behaviour in more detail.

A great article about subselects is Mosha's 2008 MDX: subselects and CREATE SUBCUBE in non-visual mode

Note what happens when you use a subselect. Implicit Exists and visual totals are applied. The key bit of information here in regards to what you are experiencing is:

2. Applies visual totals to the values of physical measures even within expressions if there are no coordinate overwrites.

In your first query SSAS applies visual totals by default. You can change your query to not do this like this:

SELECT [Customer].[Education].[(All)].ALLMEMBERS ON COLUMNS,
    Order(DrillDownLevel({[Customer].[Customer Geography].[All Customers]}), 
          ([Measures].[Internet Order Count]), 
          ASC) ON ROWS
FROM NON VISUAL (SELECT {[Customer].[Education].&[Partial High School]} ON COLUMNS FROM [Adventure Works])
WHERE [Measures].[Internet Order Count];

The NON VISUAL keyword in a SELECT statement tells SSAS to only apply the implicit Exists, but not the visual totals part. The results of the query will be the same as in the second case, but you will also see the real numbers it is ordering by.

Because you are explicitly overwriting the All member in the second query, SSAS does not apply the visual totals to this expression and orders by the total amounts for all years. However, it still displays the visual totals for the selected on ROWS measure after it evaluates the order on non-visual totals.

4
  • It's a new query with new results to add NON VISUAL. Works for [All] but will give no expected results for [Education] hierarchy (Note he is using two hierarchies of the same dimension)
    – ic3
    Jul 1, 2011 at 7:09
  • @isCube: What do you mean - did you try it? Of course it gives the expected results - it just shows the amount without the subselect filter/visual total... Jul 1, 2011 at 8:07
  • Maybe you're right, but not sure this is what carp is looking for. Let him decide :-)
    – ic3
    Jul 1, 2011 at 8:24
  • He is looking for the answer to his question. Jul 1, 2011 at 8:36
1

I'm not a SSAS specialist but this is related to attribute overwrite.

You're overwriting your sub-select in the Order function evaluation. Note, this behavior is context dependent (axes eval, calculated members and pivot). In you example the context is a function during the evaluation of the axis. The behavior is different from the evaluation of the pivot (once you're axes are known). It's complicated but the way it is.

Note that in icCube and after discussing with some MDX specialist we decided to simplify and not follow this behavior: subselect filter is always applied.

7
  • It is quite unclear what is meant by the answer. While the problem is obviously related to an attribute overwrite, I cannot see how it answers the question. In addition, it is not context dependent, and it does not make sense to say: "The behavior is different from the evaluation of the pivot" - there is no different behaviour on pivots. I'm sorry, but it does not seem like it tackles the issue accurately. Jul 1, 2011 at 5:00
  • @Boyan, it's the way SSAS completes missing hierarchies in a tuple and this depends on the context of this tuple (read carefully the 'attribute overwrite' link)
    – ic3
    Jul 1, 2011 at 7:14
  • @icCube: This has anything to do with attribute overwrites between related attributes. The subselect does not change the current coordinate and therefore does not overwrite anything. The only overwrite which is happening is the explicit overwrite of the All member in the tuple in the second argument of the ORDER statement. Jul 1, 2011 at 8:09
  • "The only overwrite which is happening is the explicit overwrite of the All member", this is the one we're speaking about.
    – ic3
    Jul 1, 2011 at 8:24
  • And what does it do? What is the effect on the rest? Jul 1, 2011 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.