Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org-mode sum values in range of rows

Tags:

emacs

org-mode

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?

like image 475
event_jr Avatar asked Apr 13 '13 02:04

event_jr


1 Answers

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.

like image 134
event_jr Avatar answered Sep 28 '22 20:09

event_jr