calculate the difference for same column in Spotfi

2019-07-25 07:43发布

问题:

I am a beginner for Spotfire. I have a problem about the difference calculation for the some column value.

I have opened a similar question for the date difference calculation, see:calculate the time difference for same column in Spotfire

how can i calculate the difference for the same column, is there any related function like DateDiff() here? for example:

id  times state
 1  12    1
 2   7    0
 3  10    1
 4  11    0
 5   6    1
 6   9    0
 7   7    1

the result could be :

id  times state  diffence
 3  10    1      -2
 5   6    1      -4
 7   7    1       1

For example : for the first difference: -2 = 10 (the third row, the state is 1) - 12(the first row, the state is 1)

thanks for your help :)

回答1:

@ZAWD - Please try this over expression.

If([state]=1,[times] - Sum([times]) over (previous([id])),null)