我可以重新编写此 MDX 查询以使用集合而不是“And”吗?

发布于 2024-09-09 02:30:31 字数 938 浏览 2 评论 0原文

with member [Measures].[BoughtDispenser] as
    Sum(Descendants([Customer].[Customer].CurrentMember, [Customer].[Customer]),
        Iif(
            (IsEmpty(([Item].[ItemNumber].&[011074], [Measures].[Sale Amount]))
            And IsEmpty(([Item].[ItemNumber].&[011069], [Measures].[Sale Amount]))
            )
            Or IsEmpty([Measures].[Sale Amount]),
            0 , 1
        )
    )
select 
{[Measures].[Sale Amount]} on columns,
non empty filter([Customer].[Customer].children, [Measures].[BoughtDispenser])
    * {[Item].[ItemNumber].members}
on rows
from [Sales]
where [EnteredDate].[Quarter].&[2010-01-01T00:00:00]
;

目的是显示同时购买了两个分配器(011069 和 011074)之一的客户所购买的所有商品。

我根据我发现进行购物篮分析的查询来计算成员。我觉得应该有一种方法可以用集合 {[Item].[ItemNumber].&[011074], [Item].[ItemNumber].&[011069]} 来编写它,而不是两个 IsEmpty 测试。我所尝试的一切最终都得到了每个客户的结果。

我的环境是 SQL Server Analysis Services 2005。

with member [Measures].[BoughtDispenser] as
    Sum(Descendants([Customer].[Customer].CurrentMember, [Customer].[Customer]),
        Iif(
            (IsEmpty(([Item].[ItemNumber].&[011074], [Measures].[Sale Amount]))
            And IsEmpty(([Item].[ItemNumber].&[011069], [Measures].[Sale Amount]))
            )
            Or IsEmpty([Measures].[Sale Amount]),
            0 , 1
        )
    )
select 
{[Measures].[Sale Amount]} on columns,
non empty filter([Customer].[Customer].children, [Measures].[BoughtDispenser])
    * {[Item].[ItemNumber].members}
on rows
from [Sales]
where [EnteredDate].[Quarter].&[2010-01-01T00:00:00]
;

The object is to show all the items purchased by customers who also bought either of the two dispensers (011069 and 011074).

I based the calculated member on a query I found to do basket analysis. I feel like there should be a way to write it with the set {[Item].[ItemNumber].&[011074], [Item].[ItemNumber].&[011069]} instead of the two IsEmpty tests. Everything I've tried ended up having every Customer in the result.

My environment is SQL Server Analysis Services 2005.

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

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

发布评论

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

评论(1

℉服软 2024-09-16 02:30:32

是的,我可以!它只需要对计算成员采取稍微不同的方法:

with member [Measures].[BoughtDispenser] as
    Sum(Descendants([Customer].[Customer].CurrentMember, [Customer].[Customer])
        * {[Item].[ItemNumber].&[011069], [Item].[ItemNumber].&[011074]},
        [Measures].[Quantity Shipped]
    )
select 
{[Measures].[Sale Amount]} on columns,
non empty filter([Customer].[Customer].children, [Measures].[BoughtDispenser])
    * {[Item].[ItemNumber].members}
on rows
from [Sales]
where [EnteredDate].[Quarter].&[2010-01-01T00:00:00]
;

Yes I can! It just required a slightly different approach to the calculated member:

with member [Measures].[BoughtDispenser] as
    Sum(Descendants([Customer].[Customer].CurrentMember, [Customer].[Customer])
        * {[Item].[ItemNumber].&[011069], [Item].[ItemNumber].&[011074]},
        [Measures].[Quantity Shipped]
    )
select 
{[Measures].[Sale Amount]} on columns,
non empty filter([Customer].[Customer].children, [Measures].[BoughtDispenser])
    * {[Item].[ItemNumber].members}
on rows
from [Sales]
where [EnteredDate].[Quarter].&[2010-01-01T00:00:00]
;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文