AVERAGE TOTALYTD给出错误的结果。 Power BI DAX

时间:2019-04-08 15:30:52

标签: powerbi dax powerbi-desktop

我只需要为Average Year To Date个索赔计算Closed。 如果我使用FILTER函数,那么它会给我正确的结果:$ 3,507.74

AVG_YTD_Indemn_Closed =
CALCULATE (
    AVERAGE ( fact_Losses[PaidIdemnity] ),
    FILTER (
        fact_Losses,
        fact_Losses[DateEntered].[Year] = YEAR ( TODAY () )
            && fact_Losses[ClaimStatus] = "Closed"
    )
)

enter image description here

但是,如果我使用TOTALYTD函数,由于某种原因,我会得到不同的结果$ 4,702.31:

AVG_YTD_Indemn_Closed1 =
CALCULATE (
    TOTALYTD ( AVERAGE ( fact_Losses[PaidIdemnity] ), dim_Date[Date] ),
    fact_Losses[ClaimStatus] = "Closed"
)

enter image description here

为什么会有如此大的差异?函数TOTALYTD如何计算与FILTER不同的结果?

1 个答案:

答案 0 :(得分:1)

here所述,

TOTALYTD (
    <EXPRESSION>,
    <DATES>
    [, <FILTER>]
    [, <YEARENDDATE>]
)

等同于

CALCULATE (
    <EXPRESSION>,
    DATESYTD ( <DATES> [, <YEARENDDATE>] )
    [, <FILTER>]
)

因此,您的TOTALYTD度量等于

AVG_YTD_Indemn_Closed1 =
CALCULATE (
    CALCULATE(
        AVERAGE ( fact_Losses[PaidIdemnity] ),
        DATESYTD( dim_Date[Date] )
    ),
    fact_Losses[ClaimStatus] = "Closed"
)

如果理顺日期关系,我建议您使用此版本,因为TOTALYTD无法容纳将来可能需要的其他过滤器,如here所述:

AVG_YTD_Indemn_Closed1 =
CALCULATE (
    AVERAGE ( fact_Losses[PaidIdemnity] ),
    DATESYTD( dim_Date[Date] ),
    fact_Losses[ClaimStatus] = "Closed"
)