event_jr
event_jr

Reputation: 17707

org-mode sum values in range of rows

It's best explained with code:

|                |  a |   b |  c |      d | row-total |
|----------------+----+-----+----+--------+-----------|
| check-sum      |  4 |   5 |  7 |   1000 |           |
|----------------+----+-----+----+--------+-----------|
|                |  1 |   2 |  2 |      1 |           |
|                |  3 |   4 |  5 |      6 |           |
|----------------+----+-----+----+--------+-----------|
| calculated-sum | ok | (1) | ok | (-993) |           |
|----------------+----+-----+----+--------+-----------|
#+TBLFM: @>$<<..$>>='(let ((sum (apply '+ '(@II..@-1))) (expected @2)) (if (= sum expected) "ok" (format "(%s)" (- sum expected))));N

I have a summary row (@5) working fine. I'd like to have the last column(in rows @2..@4) sum the values in each row. How do I express that?

Upvotes: 8

Views: 3980

Answers (1)

event_jr
event_jr

Reputation: 17707

Solved it. I had some fundamental gaps in my org-mode table knowledge

|                |  a |   b |  c |      d | row-total |
|----------------+----+-----+----+--------+-----------|
| check-sum      |  4 |   5 |  7 |   1000 |      1016 |
|----------------+----+-----+----+--------+-----------|
|                |  1 |   2 |  2 |      1 |         6 |
|                |  3 |   4 |  5 |      6 |        18 |
|----------------+----+-----+----+--------+-----------|
| calculated-sum | ok | (1) | ok | (-993) |           |
|----------------+----+-----+----+--------+-----------|
#+TBLFM: @>$<<..$>>='(let ((sum (apply '+ '(@II..@-1))) (expected @2)) (if (= sum expected) "ok" (format "(%s)" (- sum expected))));N::@2$>..@4$>=vsum($2..$5)

This [org as spreadsheet tutorial][] was helpful. [org as spreadsheet tutorial]: http://orgmode.org/worg/org-tutorials/org-spreadsheet-intro.html

Upvotes: 6

Related Questions