SSAS OLAP MDX 和关系
我是 OLAP 新手,仍然不确定如何在 2 个或更多实体之间创建关系。
我的立方体基于视图。为了简单起见,我们这样称呼它们:
viewParent(ParentID PK)
viewChild(ChildID PK,ParentID FK)
这些视图有更多字段,但它们对于这个问题并不重要。
在我的数据源中,我使用链接的 ParentID 定义了 viewParent 和 viewChild 之间的关系。
至于措施,我被迫为父母和孩子制定单独的措施。
然而,在我的 MDX 查询中,这种关系似乎并未强制执行。如果我为父项、子项选择记录计数,并为父项添加一些过滤器,则子项计数不会反映它。
SELECT {
[Measures].[ParentCount],[Measures].[ChildCount]
} ON COLUMNS
FROM [Cube]
WHERE {
(
{[Time].[Month].&[2011-06-01T00:00:00]}
,{[SomeDimension].&[Foo]}
)
}
所选的 ParentCount 是正确的,但 ChildCount 不受任何过滤器的影响(因为它们是父过滤器) 。但是,由于我定义了一个关系,我如何利用它来使用 WHERE 子句按父级过滤子级?
事实:
viewParent、viewChild
维度:
ParentDimension(包含我聚合的父视图中的属性) ChildDimension(包含我聚合的子视图中的属性)
这只是我想出的一个想法,但也许我的设计/关系已经关闭。
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 measures, 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
想通了。
查看 vs2008 中立方体的尺寸选项卡,情况变得很明显。
我的维度和度量之间的关系设置不正确。我的维度以 uniqueID 为关键,它对应于parentView uniqueID。
我将(SomeDimension 的)关系更改为不同 ID 字段(由parentView 和childView 共享)的键,我们将其称为ViewID。
我的 MDX 查询开始按预期工作。这意味着,WHERE 子句影响两个度量值组:父项和子项。
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.
可能是我对您在描述中选择的措辞过于仔细地阅读,但您可能想澄清过滤器的含义。从技术上讲,WHERE 子句不是过滤器,而是 标识结果数据集的切片器轴。如果您指的是 FILTER,那么您可能需要查看名为 FILTER 您可以将其应用于集合表达式。
您可以尝试重新排列 MDX 查询以定义两个轴 - 行和列。
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.