Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Parent Child Calculations Expand / Collapse
Author
Message
Posted Tuesday, January 06, 2009 9:52 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, March 03, 2009 6:43 PM
Points: 4, Visits: 45
I'm new to SSAS 2005, and have been tasked with creating a set of metrics for my business unit.

I have a business requirement that I've been having trouble meeting with SQL Server 2005. I've tried various combinations of EXISTING, Exists, LinkMember (with Generate), etc and haven't found a solution to this issue.

The basic need is to define a metric that counts the number of locations that are of a particular type. It seems simple enough. However, the business requirement is that the sum is ALWAYS based on the parent child hierarchy. This needs to be a calculated member for easy use and must be multi-select friendly.

My main issue (I think) is:

How do I get the current context of the parent child organizations or locations? I've tried things like EXISTING and that gives me the entire tree up to the [All] member, which is not what I want. I think doing this worked the best, but it seems VERY slow and I need to union many of these together (one for each user defined/attribute hierarchy that isn't the parent-child hierarchy) to get the full context:
Generate
(
EXISTING [Organization].[By Type].MEMBERS,
LinkMember
(
[Organization].[By Type].CURRENTMEMBER,
[Organization].[By Parent]
)
)

I've also tried the following, but it doesn't seem to do what I want it to do (and I'm completely baffled as to why).

SCOPE ([Measures].[Type1 Count]);
SCOPE([Location].[By Parent].MEMBERS);
SCOPE([Location].[Location Type].&[TYPE1].CHILDREN);
THIS = 1;
FREEZE(THIS);
END SCOPE;
FREEZE(THIS);
END SCOPE;
SCOPE([Location].[By Type].CHILDREN);
THIS =
Sum
(
Descendants
(
Generate
(
[Location].[By Type].CURRENTMEMBER.CHILDREN,
{
LinkMember
(
[Location].[By Type].CURRENTMEMBER,
[Location].[By Parent]
)
}
)
)
)
;
END SCOPE;
END SCOPE;

With the above in place in the MDXScript, the [By Parent] hierarchy works fine, but this query returns bad results:

SELECT
{
[Measures].[Type1 Count]
}
ON COLUMNS,
{
[Location].[Location Type].CHILDREN
}
ON ROWS
FROM
[My Cube]

It returns:

TYPE1 #### <-- Good number, yeah!
TYPE2 (null) <-- HUH??? Why?
TYPE3 (null) <-- HUH??? Why?
TYPE4 (null) <-- HUH??? Why?
TYPE5 (null) <-- HUH??? Why?

*sigh* It almost seems to be ignoring my request to get the Descendants of the [By Parent] hierarchy, and only works with the children of the [By Type] hierarchy (which would result in the numbers you see above). Not sure if the "current context" is getting in my way here, and if there is anyway I can "break out" of the current context for this kind of calculation? Any help would be much appreciated!

The details follow:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I have 2 dimensions that are linked via a intermediate fact table and are setup as a multi-multi relationship in the dimension usage of the cube.

One of these represents organizations in our business and the other represents physical locations. They both contain a parent child hierarchy along with a number of "attribute" and "user defined" hierarchies. The intermediate fact table is simply a link between some organization (at any level) to a location (at any level).

Each location has a type.

A simplified version of this would be:

[Organization].[Organization] <-- Hidden Main key
[Organization].[By Parent] <-- Parent Child Hierarchy
[Organization].[Organization Type]<-- Hidden Attribute Hierarchy
[Organization].[By Type] <-- User hierarchy consisting of [Organization Type], [Organization]

[Location].[Location] <-- Hidden Main key
[Location].[By Parent] <-- Parent child Hierarchy
[Location].[Location Type] <-- Hidden Attribute Hierarchy
[Location].[By Type] <-- User defined hierarchy consisting of [Location Type], [Location]

Measure Group: "Organization Location" is the association between these at any level.

~~~~~~~~~

The goal would be to create a metric named named "Type1 Count". This would compute the number of locations with an attribute of [Location Type].&[TYPE1] that are under the current context of the MDX query based on the parent-child hierarchies.

In other words, if I was to create a simple query:

SELECT
{
[Measures].[Type1 Count]
}
ON COLUMNS,
{
[Organization].[By Type].CHILDREN
}
ON ROWS
FROM
[My Cube]

Should show me the list of organization types.
The goal would be to have the count be the value of the number of type 1 locations that exist under any organization that is that type or any of its children based on the organization parent child dimension.

Note that the location associated with the various organizations may in fact be a "higher" level location and the type1 location is a child of that associated location based on the parent-child relationship in the location dimension.
Post #630735
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse