Find difference between two rows by usind Dax in Power BI

陌路散爱 提交于 2020-12-07 04:51:49

问题


I have three column one is Id(ID is same) 2nd col is amount and third is date, I want difference between two rows(amount)


回答1:


As you want to have the previous value of the date where the ID is equal, you can use the following:

Add a column,

Column4 = 
    var baseFilter = FILTER(DiffRows;DiffRows[Column1] = EARLIER(DiffRows[Column1]))
    var selectDate = CALCULATE(LASTDATE(DiffRows[Column3]);baseFilter; 
        FILTER(baseFilter; DiffRows[Column3] < EARLIER(DiffRows[Column3])))
 return 
     DiffRows[Column2] - CALCULATE(sum(DiffRows[Column2]);baseFilter; 
     FILTER(baseFilter; DiffRows[Column3] =selectDate))

First I create a basefilter to ensure the IDs are same. Next I select the date whcih is the previousdate within the set of same ids Last I use this date, to filter the correct value out of the rows.

End result:



来源:https://stackoverflow.com/questions/57710425/find-difference-between-two-rows-by-usind-dax-in-power-bi

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