聚合函数不能用于度量维度

时间:2017-03-03 09:23:41

标签: sql-server ssas mdx

如何在度量维度中使用聚合函数?

我想在工作日内创建总计。在这些日子里,我只有销售,所以我创造了旗帜:

MEMBER [Measures].[Days] as (
    COUNT(
        [Measures].[New], EXCLUDEEMPTY
    )
)

表明它。现在我需要聚合它,但是这段代码让我错误:

MEMBER [Measures].[Running] as (
    AGGREGATE(
        NULL:TAIL(EXISTING [Date].[Date].[Date].Members).Item(0), 
        [Measures].[Days]
    )
)

我希望实现以下目标:

Mon 1
Tue 2
Wed 3
Thu 4
Fri 5 
Sat 5 <- it could be also 0, NULL, doesn't matter
Sun 5 <- it could be also 0, NULL, doesn't matter
Mon 6
Tue 7
...

1 个答案:

答案 0 :(得分:1)

您根本无法对计算出的度量使用Aggregate函数。我使用以下MDX:

With
Member [Measures].[Days] as
Sum(
    Null:[Date].[Date].CurrentMember,
    IIF(
        [Measures].[New],
        1,
        Null
    )
)