MDX WHERE NOT IN() 等价于多对多维度

发布于 2024-08-15 05:50:15 字数 680 浏览 2 评论 0原文

我的多维数据集中有一个多对多维度(位于其他常规维度旁边)。当我想在行计数度量中排除事实行时,我通常在 MDX 中执行类似以下操作,

SELECT [Measures].[Row Count] on 0
FROM cube
WHERE ([dimension].[attribute].Children - [dimension].[attribute].&[value])

这可能看起来比这个简单示例中所需的更复杂,但在这种情况下,WHERE 有时可能会增长,还包括 UNION。

所以这适用于常规维度,但现在我有一个多对多维度。如果我执行上面的技巧,它不会产生所需的结果,即我想排除多对多维度中具有该特定属性的所有行。

实际上,它完全按照 MDX 的要求执行,即计算所有行,但忽略指定的属性。由于事实表中的一行可以在多对多维度中具有多个属性,因此该行仍将被计数。

这不是我需要的,我需要它显式排除具有该维度属性值的行。另外,我可能会排除多个值。所以我需要的是类似于 T-SQL 的 WHERE .. NOT IN (...)

我意识到我可以从 [attribute].all 和 [attribute].&[value] 中减去结果值,但是UNION 多个 WHERE 语句时将不再起作用。

有人对如何解决这个问题有好主意吗?

提前致谢,

达美航空

I have a many-to-many dimension in my cube (next to other regular dimensions). When I want to exclude fact rows in my row count measure, I usually do something like the following in MDX

SELECT [Measures].[Row Count] on 0
FROM cube
WHERE ([dimension].[attribute].Children - [dimension].[attribute].&[value])

This might seem more complicated than needed in this simple example, but in this case the WHERE can grow sometimes, also including UNIONs.

So this works for regular dimensions, but now I have a many-to-many dimension. If I perform the trick above it does not produce the desired result, namely I want to exclude all rows that have that specific attribute in the many-to-many dimension.

Actually it does exactly what the MDX asks, namely count all rows, but ignore the specified attribute. Since a row in the fact table can have multiple attributes in a many-to-many dimension, the row will still be counted.

That's not what I need, I need it to explicitly exclude rows that have that dimension attribute value. Also, I might exclude multiple values. So what I need is something similar to T-SQL's WHERE .. NOT IN (...)

I realize that I can just subtract the resulting values from [attribute].all and [attribute].&[value], but that won't work any more when UNIONing multiple WHERE statements.

Anybody got a good idea on how to solve this?

Thanks in advance,

Delta

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦途 2024-08-22 05:50:15

我还没有测试过这一点,但我认为如果您有一个与行具有相同粒度级别的属性(因此可能作为事实关系实现),您就可以做到这一点。

因此,如果您想计算没有自行车产品类别的订单数量(假设 OrderID 和类别之间存在 M2M 关系),那么类似以下内容应该有效。 (您可以在联机丛书中找到有关 EXISTS 函数的更多信息)

[Orders].[Order ID].[Order ID].Members 
- EXISTS([Orders].[Order ID].[Order ID].Members
       , [Product].[Category].&[Bikes]
       , "Order Facts")

尽管它可能会非常慢,因为此类查询迫使 SSAS 引擎从低级别添加大量事实。

I have not tested this, but I think you could do this if you had an attribute that was at the same level of granularity as the rows (so probably implemented as a fact relationship).

So if you wanted to count the number of orders that did NOT have a product category of bikes (assuming a M2M relationship between OrderID and Category) then something like the following should work. (you can find more info on the EXISTS function in Books Online)

[Orders].[Order ID].[Order ID].Members 
- EXISTS([Orders].[Order ID].[Order ID].Members
       , [Product].[Category].&[Bikes]
       , "Order Facts")

Although it could be quite slow as this sort of query is forcing the SSAS engine to add up a lot of facts from a low level.

缪败 2024-08-22 05:50:15

您尝试过 EXCEPT 命令吗?它的语法如下:


EXCEPT({我想要的集合},{我不想要的成员集合})

Have you tried the EXCEPT command? It's syntax is like the following:


EXCEPT({the set i want}, {a set of members i dont want})

带上头具痛哭 2024-08-22 05:50:15

您可以使用过滤器功能:

SELECT [Measures].[Row Count] on 0
FROM [cube]
WHERE Filter([dimension].[attribute].Children, [dimension].CurrentMember.MemberValue <> value)

You could use the Filter function:

SELECT [Measures].[Row Count] on 0
FROM [cube]
WHERE Filter([dimension].[attribute].Children, [dimension].CurrentMember.MemberValue <> value)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文