我有一个简单的DAX公式,我想用它来区分符合某个标准的客户数量。我有一个表格来定义这些标准,即Tiers我在power bi上这样做,这是我正在使用的措施;
MTierB =
var y = SUM('Brand Tiers'[TierB]),
var x = SUM('Brand Tiers'[TierA])
return CALCULATE(DISTINCTCOUNT('Sales By Customers'[CUSTOMER_StoreCode]),
KEEPFILTERS(FILTER('Sales By Customers', 'Sales By Customers'[Total Sales in
MSU] >= y AND <=x )))
我收到语法错误。 AND运算符用红色下划线,我不明白为什么?请帮忙
答案 0 :(得分:0)
在DAX中,AND
是AND(a,b)
表示“a和b”的函数。 (Reference)
但您可以使用&&
作为逻辑连接。也就是AND(a,b) == a && b
在您的情况下,您需要将度量的FILTER
部分看作这样
FILTER('Sales By Customers',
'Sales By Customers'[Total Sales in MSU] >= y &&
'Sales By Customers'[Total Sales in MSU] <= x)
或者像这样
FILTER('Sales By Customers',
AND('Sales By Customers'[Total Sales in MSU] >= y,
'Sales By Customers'[Total Sales in MSU] <= x))
答案 1 :(得分:0)
此外,变量语句之间没有逗号。
MTierB =
VAR y = SUM ( 'Brand Tiers'[TierB] ) // no comma
VAR x = SUM ( 'Brand Tiers'[TierA] )
RETURN
CALCULATE (
DISTINCTCOUNT ( 'Sales By Customers'[CUSTOMER_StoreCode] ),
KEEPFILTERS (
FILTER (
'Sales By Customers',
'Sales By Customers'[Total Sales in MSU] >= y
&& 'Sales By Customers'[Total Sales in MSU] <= x
)
)
)