2014-06-01 13:57 GMT+02:00 Michael Brand <michael.ch.brand@gmail.com>:
On Sun, Jun 1, 2014 at 1:38 PM, Cecil Westerhof <cldwesterhof@gmail.com> wrote:
> I like to calculate in a table the difference between the value in a field
> in the current row and the previous field. How would I do that?
>
> Something like:
> |-------+------------|
> | value | difference |
> |-------+------------|
> |    12 |            |
> |    15 |          3 |
> |    83 |         68 |
> |    87 |          4 |
> |    85 |         -2 |
> |-------+------------|

For such cases I prefer vlen():

#+TBLFM: $2 = if(vlen(@II..@0) == 1, string(""), $1 - @-1$1); E

​Combining it with your previous help I now have (not every field will be filled, and the table is a little different):
#+TBLFM: @-I$4..@+I$4 = if("$3" == "nan", string(""), $3 - $2) ; E f-1 :: @-I$5..@+I$5 = if(vlen(@II..@0) == 1 || "$3" == "nan", string(""), $3 - @-1$3); E f-1​
 

​At the moment this is good enough. But what if I would want to know the difference between the previous filled one, divided by the ​distance?

For example:
|-------+------------|
| value | difference |
|-------+------------|
|    12 |            |
|    15 |          3 |
|       |            |
|    83 |         34 |
|       |            |
|       |            |
|       |            |
|    87 |          1 |
|       |            |
|       |            |
|       |            |
|    85 |       -0.5 |
|       |            |
|-------+------------|

--
Cecil Westerhof