Forum Discussion

rubymaya's avatar
rubymaya
Helper III
6 years ago
Solved

Calculated column for getting difference between current and previous values

Hi experts,

I have issue with getting my calculated column to calculate the difference between current vs previous row/date

See the screenshot, what i want to achieve is that :

Difference between Qty for 6-Feb for Area PCBA_4C with 0-29 Days aging with the one in 5-Feb would be 41-4 = 37

ReportDate   Area             Aging    Qty     PrevValue    Difference

5-Feb            PCBA_4C      0-29       4         0                  4

6-Feb            PCBA_4C      0-29      41        4                  37 ---> 41(currrent) - 4(previousrowday) *bear in mind it should not be date-1 date earlier might not be in the record

 

So far my dax to get the prev value isnot working 😞

I already assigned Index for each row but not working.

Appreciate any help

 

PrevValue = SUMX(
Fact_CUST_TB_WIP_BONEPILE_INOUT,
var myIndex = Fact_CUST_TB_WIP_BONEPILE_INOUT[Index]
var myRecord = Fact_CUST_TB_WIP_BONEPILE_INOUT[QTY]
var previousIndex =
CALCULATE(
max(Fact_CUST_TB_WIP_BONEPILE_INOUT[Index]),
FILTER(Fact_CUST_TB_WIP_BONEPILE_INOUT,Fact_CUST_TB_WIP_BONEPILE_INOUT[QTY] = myRecord && Fact_CUST_TB_WIP_BONEPILE_INOUT[Index] < myIndex )
)

var previousqty =
CALCULATE(
MAX( Fact_CUST_TB_WIP_BONEPILE_INOUT[QTY] ),
filter (
Fact_CUST_TB_WIP_BONEPILE_INOUT,
Fact_CUST_TB_WIP_BONEPILE_INOUT[Index] = previousIndex
&& Fact_CUST_TB_WIP_BONEPILE_INOUT[REPORT_DATE] = myRecord
)
)

return previousIndex

)

 

 

9 Replies