MDX - 具有不相关维度的计算成员

时间:2013-10-31 11:33:04

标签: ssas mdx olap

我有两个措施: [测量]。[ChildCount]和[测量]。[购买] 和两个维度: [买家]和[卖家]。

[Measure]。[ChildCount]使用[Buyers]维度来计算每个买方的子组织。 [措施]。[买入]使用[买家]和[卖家]来计算从[卖家]到[买家]的购买。

我想要实现的是选择所有买家购买ChildCount< 1和ChildCount的买家> 0

目前这些查询工作正常: 第一个计算每个发件人/买家的购买行为:

SELECT [Measure].[Buyings] on COLUMNS,
[Sellers].[Code].[Code] *
[Buyers].[Code].[Code] ON ROWS
FROM MyCube

第二个计算有和没有孩子的买家的购买:

WITH MEMBER [Measure].[BuyingsWithChilds]
as SUM
(
FILTER([Buyers].[Code].[Code],[Measure].[ChildCount]>0),
[Measure].[Buyings]
)
MEMBER [Measure].[BuyingsWithoutChilds] 
as SUM
(
FILTER([Buyers].[Code].[Code],[Measure].[ChildCount]<1),
[Measure].[Buyings]
)
SELECT
{
[Measure].[BuyingsWithChilds],
[Measure].[BuyingsWithoutChilds]
} ON COLUMNS,
[Buyers].[Code].[Code] ON ROWS
FROM MyCube

但是如果我尝试将这些查询组合成所需的查询:

    WITH MEMBER [Measure].[BuyingsWithChilds]
    as SUM
    (
    FILTER([Buyers].[Code].[Code],[Measure].[ChildCount]>0),
    [Measure].[Buyings]
    )
    MEMBER [Measure].[BuyingsWithoutChilds] 
    as SUM
    (
    FILTER([Buyers].[Code].[Code],[Measure].[ChildCount]<1),
    [Measure].[Buyings]
    )
    SELECT
    {
    [Measure].[BuyingsWithChilds],
    [Measure].[BuyingsWithoutChilds]
    } ON COLUMNS,
    [Sellers].[Code].[Code] ON ROWS
    FROM MyCube

此查询的执行需要永远。 是否可以修复或优化它?

1 个答案:

答案 0 :(得分:0)

如果您将[Measure].[ChildCount]>0[Measure].[ChildCount]<1转换为类似“HasChildren”的属性,那么您可以避免Filter功能,该功能通常很慢,而且您使用两次。

然后您的WITH子句将简化为

WITH MEMBER [Measure].[BuyingsWithChilds]
as ([Buyers].[HasChildren].[Yes], [Measure].[Buyings])
MEMBER [Measure].[BuyingsWithoutChilds]
as ([Buyers].[HasChildren].[No], [Measure].[Buyings])

应该快得多,因为它使用[Measure].[Buyings]的标准聚合。