Sumif equivalent in PowerBI doesn't work properly with DAX function

帅比萌擦擦* 提交于 2019-12-24 06:36:47

问题


I try to use SUMIF equivalent in PowerBI. I have read already a lot of similar topics describing the usage of CALCULATE and SUM combined with FILTER functions. But none of them could help me with my problem.

What I want to do:

A production line writes a time stamp into a CSV file when it starts an event (e.g. machine starts, machine stopps etc.). The CSV file is processed by PowerQuery in a way that all start dates are available in one column of a table. The column is called "Event Start".

To further analyze the events of the machine, I would like to add another column "Event End" that contains also the end date of each event. The end date is not provided by the CSV file but it is equal to the start date of the next event.

So what I need to do is to have a value in row n, column 2 that is taken from row n+1, column 1. In Excel, very easy to do so... One solution (not the best one - I know) is to use SUMIF together with an Index column and Index+1 column:

I came up with the idea to use SUMIF because I know that there is an equivalent function with DAX expression (CALCULATE, SUM and filters). Unfortunately in this case all the examples given in other threads don't work.

Could anybody help me with this? Maybe there is another DAX function available to solve this issue.


回答1:


Here are two options. The first one returns the [Start Event] where [Index] is 1 higher than [Index] in the current row.

The second one returns the smallest [Start Event] that is greater than the [Start Event] in the current row.

End Event =
CALCULATE (
    MAX ( 'Table1'[Start Event] ),
    FILTER ( 'Table1', 'Table1'[index] = EARLIER ( 'Table1'[index] ) + 1 )
)  

End Event 2 =
CALCULATE (
    MIN ( 'Table1'[Start Event] ),
    FILTER ( 'Table1', 'Table1'[Start Event] > EARLIER ( 'Table1'[Start Event] ) )
)



来源:https://stackoverflow.com/questions/56892922/sumif-equivalent-in-powerbi-doesnt-work-properly-with-dax-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!