I need to summary a table according to one column and sum the specific rows of another column.
e.g. The summary table is generated from the input table. input table column 1 grouped to IN and OUT, column 2 is the sum of IN or OUT columns.
#+NAME: summary
| Item | Value |
|-------+-------|
| IN | $5.0 |
| OUT | $7.0 |
| Total | $13.0 |
#+NAME: input
| Item | Value |
|------+-------|
| IN | $1.5 |
| OUT | $2.5 |
| IN | $3.5 |
| OUT | $4.5 |
|------+-------|
#+BEGIN_SRC elisp :results output :var input=input
(let (item (in 0)(out 0))
(dolist (line input)
(setq item (car line))
(setq val (string-to-number (substring (cadr line) 1) 10))
(if (string= item "OUT")
(progn
(setq out (+ out val))))
(if (string= item "IN")
(progn
(setq in (+ in val)))))
(print in)
(print out)
(print (+ in out))
)
#+END_SRC
#+RESULTS:
:
: 5.0
:
: 7.0
:
: 12.0
Currently, I use elisp to calculate it but I know formula maybe better but I don't know how to do it!