问题
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