POWER BI:基于多个过滤器创建计算字段

POWER BI: Creating a calculated field based on multiple filters

我是 Power Bi 的新手,在各种在线帮助论坛中进行了搜索,但未能找到与我的相似的论坛。因此在这里张贴这个。不确定这是一个相当简单的还是复杂的(如我所想!)

我有 3 列:'Event'、'Screen' 和 'Time'(与下面类似)

我想做一个计算如下:

(2*count of "NameSubmitted" occurrences in Event) - (AVG Time of corresponding "NameSubmitted" (from Event) * count of "NameSubmitted" occurrences in Event)

+

(2*count of "AddressAdded" occurrences in Event) - (AVG Time of corresponding "AddAddress" (from screen) * count of "AddressAdded" occurrences in Event)

+

(2*count of "OrderCreated" occurrences in Event) - (AVG Time of corresponding sum of "Orders"+"OrderDetail"+"OrderConfirmation" (from screen) * count of "OrderCreated" occurrences in Event)`

我的做法:

我尝试使用以下 IF() 函数计算创建一个新列但没有成功(如下所示开始)并收到以下错误:

Calc = CALCULATE( (2*SUM(IF(Table[Event] = "NameSubmitted",1,BLANK()))) - AVERAGE(IF(Table[Event] = "NameSubmitted") )) .....

Error: The SUM function only accepts a column reference as an argument

非常感谢任何帮助。

我不会给出完整的答案,但最后一段应该是这样的:

= 2 * COUNTROWS(FILTER(Table1, Table1[Event] = "OrderCreated"))
    - CALCULATE(AVERAGE(Table1[Time]),
          Table1[Screen] IN {"Orders", "OrderDetail", "OrderConfirmation"})
    * COUNTROWS(FILTER(Table1, Table1[Event] = "OrderCreated"))

注意:如果你分解出 COUNTROWS():

会更有效率
= COUNTROWS(FILTER(Table1, Table1[Event] = "OrderCreated")) *
  (2 - CALCULATE(AVERAGE(Table1[Time]),
           Table1[Screen] IN {"Orders", "OrderDetail", "OrderConfirmation"}))

你应该可以从那里得到其余的。


有多种方法可以代替 COUNTROWS() 来计算出现次数。最接近您尝试的可能是这样的:

= SUMX(Table1, IF(Table1[Event]="NameSubmitted", 1, BLANK()))