开发者

SSAS OLAP MDX and relationships

I new to OLAP, and still not sure how to create a relationship between 2 or more entities.

I am basing my cube on views. For simplicity sake let's call them like this:

viewParent (ParentID PK)

viewChild (ChildID PK, ParentID FK)

these views have more fields, but they're not important for this question.

in my data source, i defined a relationship between viewParent and viewChild using ParentID for the link.

As for me开发者_开发知识库asures, i was forced to create separate measures for Parent and Child.

in my MDX query however, the relationship does not seem to be enforced. If i select record count for parent, child, and add some filters for the parent, the child count is not reflecting it..

SELECT {
    [Measures].[ParentCount],[Measures].[ChildCount]
} ON COLUMNS
FROM [Cube]
WHERE {
    (
    {[Time].[Month].&[2011-06-01T00:00:00]}
    ,{[SomeDimension].&[Foo]}
    )
}

the selected ParentCount is correct, but ChildCount is not affected by any of the filters (because they are parent filters). However, since i defined a relationship, how can i take advantage of that to filter children by parent using a WHERE clause?

Facts:

viewParent, viewChild

Dimensions:

ParentDimension (contains attributes from parent view that i'd aggregate on) ChildDimension (contains attributes from child view that i'd aggregate on)

This is just an idea i came up with, but maybe my design/relationship is off.


Figured it out.

Looking at the dimensions tab of the cube in vs2008 it became obvious.

my relationship between dimension and the measures was not set-up correctly. My dimension was keyed on uniqueID which corresponded to parentView uniqueID.

I changed the relationship (of SomeDimension) to key on a different ID field (shared by both parentView and childView) let's call it ViewID.

and my MDX queries started working as expected. Meaning, WHERE clause affected both measure groups: parent and child.


It may be that I am reading too closely into the wording you chose in your description, but you may want to clarify what you mean by filters. Technically the WHERE clause isn't a filter but instead identifies the slicer axis for the resulting data set. If you mean FILTER, then you may want to look into the MDX function named FILTER which you can apply to a set expression.

What you may try is rearranging your MDX query to define BOTH Axis - ROWS and COLUMNS.

SELECT 
{
    [Measures].[ParentCount],[Measures].[ChildCount]
} ON COLUMNS,
{
    [SomeDimension].&[Foo]
} ON ROWS
FROM [Cube]
WHERE ([Time].[Month].&[2011-06-01T00:00:00])
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜