PowerBI.两个看似相等的计算量度实际上是不同的.为什么? [英] PowerBI. Two apparently equal calculated measures are actually different. why?

查看:74
本文介绍了PowerBI.两个看似相等的计算量度实际上是不同的.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最终在Power BI中得到以下两个计算得出的量度,它们在语义上看起来是相等的,但是每个产生不同的结果.我想知道为什么.Power BI如何计算它们,以便产生不同的结果?

I end up with the following two calculated measures in Power BI which look semantically equal, but each produces a different result. I'd like to understand why. How does Power BI calculate each so they produce different results?

measure1 =
VAR var1 =
    CALCULATE ( [measure], table[column_1] = "some value in column 1" )
VAR var2 =
    CALCULATE ( var1, table[column_2] = "some value in column 2" )
RETURN
    var2

从字面上看,将var1的RHS复制到var2中的值中.

Literally, copy the RHS of var1 into its value in var2.

measure2 =
VAR var2 =
    CALCULATE (
        CALCULATE ( [measure], table[column_1] = "some value in column 1" ),
        table[column_2] = "some value in column 2"
    )
RETURN
    var2

我正在使用的视觉效果是一个矩阵,其中的行是 table [column_2] ,不知道这是否重要.无论如何,我会说这两个表达式应该是相等的...但是它们不是

The visual I'm using is a matrix in which the rows are table[column_2], don't know if it matters. In whatever case I'd say this two expresions should be equivalent... but they aren't

推荐答案

使用 VAR 定义变量时,以后引用该值时,会将其视为常量.

When you define a variable with VAR, that value is treated as a constant when referenced later.

因此,您的第一个方法是 var2 var1 相同,因为通过使用CALCULATE调整过滤器上下文不会更改常量.

Therefore, in your first measure, var2 is the same as var1 since a constant is not changed by adjusting the filter context with CALCULATE.

如果您没有定义临时变量,而是将 var1 定义为单独的 measure ,那么它将按照您在第一个示例中的预期运行.

If instead of defining a temporary variable, you defined var1 as a separate measure, then it would function as you expected it to in your first example.

请注意,您可以使用多个条件,而不是嵌套CALCULATE函数:

As a side note, you can use multiple conditions rather than nesting CALCULATE functions:

measure3 =
CALCULATE (
    [measure],
    table[column_1] = "some value in column 1",
    table[column_2] = "some value in column 2"
)

这篇关于PowerBI.两个看似相等的计算量度实际上是不同的.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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