SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Parent Child Calculations


Parent Child Calculations

Author
Message
awood-935115
awood-935115
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 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). Sad

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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search