Difference with previous row

Hello,

There is a way to calculate the difference between current value and previous row value (grouped by some columns) ?
eg.
input table:
col1, col2
a, 10
a, 12
a, 21
b, 10
c, 99

and in another table we need a column like col3:
col1, col2, col3
a, 10, 0
a, 12, 2
a, 21, 9
b, 10, 0
c, 99, 0

I appreciate any help,
Radu.

Yes, just shift columns down to bring in values from the previous row into the current row. Then, if the previous row is in the same group, calculate the difference. Otherwise, set to 0.

Here you go:
row-diff-grouped.morph (4.2 KB)

1 Like

Many thanks. Solve the problem!