简体   繁体   English

Power BI Dax 度量

[英]Power BI Dax Measure

I'm new to Power BI and creating measures with DAX.我是 Power BI 的新手,我是使用 DAX 创建度量的。 I have two tables ('Visits' and 'Customers').我有两个表(“访问”和“客户”)。 I want to get a distinct count for the [customer_id] in the Visits table where 'Visits'[closedFlag] = 1 and 'Customers'[formFLG] = 1. Basically, I'm trying to create a measure that counts the customer id based on two conditions from two different tables.我想获得访问表中 [customer_id] 的不同计数,其中 'Visits'[closedFlag] = 1 和 'Customers'[formFLG] = 1。基本上,我正在尝试创建一个计算客户 ID 的度量基于来自两个不同表的两个条件。 There is an one to many relationship between Customers and Visits.客户和访问之间存在一对多的关系。 This is the DAX measure I tried to create...这是我尝试创建的 DAX 度量...

= CALCULATE(DISTINCTCOUNT('Visits'[CustomerID]),'Visits','Visits'[closedFLG] = 1 && 'Customers'[formFLG] = 1) = CALCULATE(DISTINCTCOUNT('Visits'[CustomerID]),'Visits','Visits'[closedFLG] = 1 && 'Customers'[formFLG] = 1)

But I get the following error... "The expression contains columns from multiple tables, but only columns from a single table can be used in a True/False expression that is used as a table filter expression.但是我收到以下错误...“表达式包含来自多个表的列,但只有来自单个表的列才能用于用作表过滤器表达式的 True/False 表达式。

Thanks for any help with this I can receive.感谢您对此的任何帮助。

You are using the CALCULATE() wrong here.您在这里错误地使用了 CALCULATE()。 You don't need to specifically name the table 'visits' after your DISTINCTCOUNT() and you can not use the && operator when looking at two different tables.您不需要在 DISTINCTCOUNT() 之后专门命名表“访问”,并且在查看两个不同的表时不能使用 && 运算符。 (Mind that this is possible if you would be looking at two columns from the 'Visits' table.) (请注意,如果您要查看“访问次数”表中的两列,这是可能的。)

This is easy to fix by getting rid of some of your syntax or by using the FILTER() syntax, which would result in the following two solutions:通过删除一些语法或使用 FILTER() 语法,这很容易解决,这将导致以下两种解决方案:

[MeasureName] = CALCULATE(
DISTINCTCOUNT('Visits'[CustomerID]),
'Visits'[closedFLG] = 1,
'Customers'[formFLG] = 1)
[MeasureName] = CALCULATE(
DISTINCTCOUNT('Visits'[CustomerID]),
FILTER('Visits','Visits'[closedFLG] = 1), 
FILTER('Customers', 'Customers'[formFLG] = 1))                            

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM