为什么结果取决于度量的定义位置?

Why does the result depend on where the measure is defined?

我正在尝试以下两个查询

查询 1:

DEFINE
MEASURE 'Product'[x] = COUNTROWS(FILTER('Product', 'Product'[Color]="Red"))
EVALUATE
    ADDCOLUMNS(VALUES('Product'[Brand]), "count",  [x])

查询 2:

EVALUATE
ADDCOLUMNS(VALUES('Product'[Brand]), "count",  COUNTROWS(FILTER('Product', 'Product'[Color]="Red")))

在 dax.do 中,结果不同。我真的不明白为什么。有什么想法吗?

特别是第一个查询returns

同时查询 2 returns

不同之处在于,当您在另一个度量中调用任何度量时,CALCULATE 会环绕(调用的)度量。

这会导致上下文转换,即将活动行上下文转换为用于计算的筛选器上下文。

使用此公式 returns 与您的查询 1 相同:

EVALUATE
ADDCOLUMNS(VALUES('Product'[Brand]), "count",  CALCULATE ( COUNTROWS(FILTER('Product', 'Product'[Color]="Red"))))