Mega Search
23.2 Million


Sign Up

Make a donation  
Partial solution to "SELECT DISTINCT" in MDX problem - how t  
News Group: microsoft.public.sqlserver.olap

I have a fairly complex cube with numerous dimensions, the principal
one having the following hierarchy

[Class] > [SubClass1] > [SubClass2] > [Primary Ref] > [Secondary Ref]

[Secondary ref] is not a leaf. I wish it were.

The hierarchy also has a couple of attributes which are descriptions
of the subclasses.

The table has a number of financials and a [Transaction Count] member.

I need to be able to give a number of distinct [Primary Ref]s and
[Secondary Ref]s in the cube as two calculated members. I can't use
[Transaction Count] as the fact table contains multiple entries for
each reference. It appears I'm not the first to ask about this, but
all the suggestions I've tried either don't work or don't seem to
apply to calculated members.

I'd rather avoid having to write C# functions to get this done.

My solution has been the following:

WITH MEMBER [SecondaryRefCount] AS
 IIF(DISTINCTCOUNT(DESCENDANTS([Class].[Class of
Business].CurrentMember,[Class].[ClassHierarchy].[Secondary
Ref],SELF))=0,
  Null,
  DISTINCTCOUNT(DESCENDANTS([Class].[Class of Business].CurrentMember,
[Class].[ClassHierarchy].[Secondary Ref],SELF))
)

There's a similar calc member for the primary ref.

If I use the Class hierarchy itself, and/or put attributes /
hierarchies from other dimensions on the axes they seem to work fine.

This seems to work fine in all scenarios but one. If I put one of the
non-hierarchy attributes ([SubClass1Description]) on an axis, the
function fails to filter on that value and I get the totals for all
SubClass1Descriptions. Somehow there doesn't seem to be a causal link
between the attribute at the hierarchy, and I have no idea how to
simulate one.

I can get round this (sort of) by removing the attibutes from my Class
dimension, but I'd rather not. It appears what I need to do is tie the
[SubClass1Description] and [SubClass2Description] attributes to the
[Class].[ClassHierarchy], but I don't want them to be visible there so
I can't include them in the hierarchy itself.

Can anyone help? I'm SOOO close to getting this to work exactly as
required.

Many thanks!

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 30-Jan-2012, at 3:14 AM EST
From: Mike