DAX:请解释为什么此变量变量无法正常工作 [英] DAX: please explain why this measure with a variable will not work

查看:85
本文介绍了DAX:请解释为什么此变量变量无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.此措施将不起作用.你能解释一下为什么不可以吗?

hello. this measure will not work. can you please explain why not?

推荐答案

您的度量不起作用,因为您将变量用作CALCULATE的表达参数:变量是不可变的;这意味着一旦定义了行为就如同一个常量,这意味着它们的值无法更改.

Your measure does not work because you are using a variable as the expression parameter of CALCULATE: variables are immutable; that means that once defined the behave like a constant, that means that their value cannot be changed.

在定义变量而不是引用变量的地方评估变量;因此,它们的值不受CALCULATE中修改的过滤器上下文的影响.

Variables are evaluated where they are defined and not where they are referenced; therefore their value is not affected by modified filter context in CALCULATE.

要检查您的公式,请直接使用度量值而不是变量

To check your formula use directly the measure instead of the variable

Sales Last Year =
CALCULATE(
    [Total Sales],
    SAMEPERIODLASTYEAR( CalendarTable[Date] )
)

通过这种方式,可以在由 SAMEPERIODLASTYEAR(CalendarTable [Date])

This way the [Total Sales] is evaluated in the filter context altered by SAMEPERIODLASTYEAR( CalendarTable[Date] )

改为使用变量,例如in

using a variable instead, like in

Sales Last Year (wrong) =
VAR Sales = [Total Sales]
RETURN
    CALCULATE(
        Sales,
        SAMEPERIODLASTYEAR( CalendarTable[Date] )
    )

使用要在其中评估度量的过滤器上下文在 CALCULATE 之外对Sales进行评估.假定此值为 1000 ,则以下 CALCULATE 表达式等效于

makes Sales to be evaluated outside CALCULATE, using the filter context existing where the measure is evaluated. Assuming that this value is 1000 the following CALCULATE expression is equivalent to

    CALCULATE(
        1000,
        SAMEPERIODLASTYEAR( CalendarTable[Date] )
    )

无论 SAMEPERIODLASTYEAR 是什么,都会返回1000

that will return 1000 whatever the SAMEPERIODLASTYEAR is

这篇关于DAX:请解释为什么此变量变量无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆