将FILTER添加到AVERAGEX函数会导致错误Power BI

时间:2019-06-21 18:30:09

标签: powerbi dax powerbi-desktop

我有以下衡量标准:

AVG Closed Claims =
AVERAGEX (
    SUMMARIZE (
        fact_Loss,
        fact_Loss[ClosedMMYY],
        "Average", COUNT ( fact_Loss[ClaimID] )
    ),
    [Average]
)

ClosedMMYYblank时,我只需要添加过滤器语句以消除值

所以我正在尝试类似的操作:

AVG Closed Claims =
CALCULATE (
    AVERAGEX (
        SUMMARIZE (
            FILTER ( fact_Loss, fact_Loss[ClosedMMYY] <> BLANK () ),
            fact_Loss,
            fact_Loss[ClosedMMYY],
            "Average", COUNT ( fact_Loss[ClaimID] )
        ),
        [Average]
    )
)

但这给我一个错误。

FILTER应该放在哪里?

1 个答案:

答案 0 :(得分:2)

您现在在SUMMARIZE中有两个表。刚刚使用了过滤后的一个。

AVG Closed Claims =
CALCULATE (
    AVERAGEX (
        SUMMARIZE (
            FILTER ( fact_Loss, fact_Loss[ClosedMMYY] <> BLANK () ),
            -- Remove this one => fact_Loss,
            fact_Loss[ClosedMMYY],
            "Average", COUNT ( fact_Loss[ClaimID] )
        ),
        [Average]
    )
)

在上面,您不需要CALCULATE。如果您使用的是CALCULATE,请这样写:

AVG Closed Claims =
CALCULATE (
    AVERAGEX (
        SUMMARIZE (
            fact_Loss,
            fact_Loss[ClosedMMYY],
            "Average", COUNT ( fact_Loss[ClaimID] )
        ),
        [Average]
    ),
    fact_Loss[ClosedMMYY] <> BLANK ()
)

否则,这是

AVG Closed Claims =
AVERAGEX (
    SUMMARIZE (
        FILTER ( fact_Loss, fact_Loss[ClosedMMYY] <> BLANK () ),
        fact_Loss[ClosedMMYY],
        "Average", COUNT ( fact_Loss[ClaimID] )
    ),
    [Average]
)

请注意,由于CALCULATE布尔过滤器替换该列用于过滤上下文,而不仅仅是添加其他条件,因此它们并不完全等效。