4

In org-mode is it possible to generate a table, where there is a column which contains a value computed from values in the other columns and which contains the sum of these values?

More specifically, at the moment I have a table with seven columns, where the last two columns contain values computed from values in the other columns using the following formula:

#+TBLFM: $6=$4-$3;t::$7=$4-$3-$2;t

I would like to include the sum of the last column. Is this possible? If yes, how can this be achieved? When I tried to do this I always got zero. Ideally I would like to have the sum somewhere outside of the table or in the last row (even if I add new rows).

5

You should use cell formulas (prefixed by := instead of =) for your results.

The example below gives the sum of the last column both at the first and the last rows.

|      |      | 8   |
| Col1 | Col2 | Sum |
|------+------+-----|
| 1    | 3    | 4   |
| 2    | 8    | 10  |
| 3    | -9   | -6  |
|------+------+-----|
|      |      | 8   |
#+TBLFM: $3=$1+$2::@1$3=vsum(@I..@II)::@6$3=vsum(@I..@II)

vsum sums a vector of numbers; @I and @II refer to the first and second hlines.

  • I still get zero as a result. Is it possible that the reason is the ;t part which I need since I am dealing with times. Adding this also "breaks" your example. – Christian Nov 11 '16 at 14:52
  • Tested my example with ;T mode on all formulas and times for all cells, and it works OK. Note the uppercase T (lowercase t gives results in decimal hours instead of H:M:S). – Juancho Nov 11 '16 at 15:46
  • Thanks, I found the problem: I started the table with |-----.... and then it does not work but without this line it does. (By the way, I really want ;t instead of ;T since I want to the total time in decimal hours). – Christian Nov 11 '16 at 16:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.