2

How can I recalculate this entire table?

If I type C-u C-c C-c with point at the start of the 'End Nubbin' line, only the formula that computes the total above the line containing 'other' gets recalculated, and not the other formulae.

I can get the result I want by placing point on each TBLFM line in turn and typing C-c C-c. I would like to get that same result with a single command.

|-------------+---------|
| Other       |         |
|-------------+---------|
| Spam        |     100 |
| Ham         |      75 |
|             |         |
| ^           |   other |
|-------------+---------|
| Widgets     |         |
|-------------+---------|
| End Nubbin  |      10 |
| Side Nubbin |      20 |
|             |         |
| ^           | widgets |
|-------------+---------|
| Total       |         |
|-------------+---------|
|             |         |
| ^           |   total |
|-------------+---------|
#+TBLFM: $other=vsum(@-I..@-1)
#+TBLFM: $widgets=vsum(@-I..@-1)
#+TBLFM: $total=$other+$widgets
Croad Langshan
  • 3,192
  • 14
  • 42

1 Answers1

8

There are three issues here I think. First, you need to put the markers ^ in a dedicated column, not mixed in like you have. Second, you need to have all your formulae in a single line. Fixing those, you would have:

|---+-------------+---------|
|   | Other       |         |
|---+-------------+---------|
|   | Spam        |     100 |
|   | Ham         |      75 |
|   |             |         |
| ^ |             |   other |
|---+-------------+---------|
|   | Widgets     |         |
|---+-------------+---------|
|   | End Nubbin  |      10 |
|   | Side Nubbin |      20 |
|   |             |         |
| ^ |             | widgets |
|---+-------------+---------|
|   | Total       |         |
|---+-------------+---------|
|   |             |         |
| ^ |             |   total |
|---+-------------+---------|
#+TBLFM: $other=vsum(@-I..@-1)::$widgets=vsum(@-I..@-1)::$total=$other+$widgets

But then there is the third issue, which is that you need to double up the C-u argument: either C-u C-u C-c C-c or C-u C-u C-c *. This is because you have one formula that references the results of another formula, so multiple passes are needed.

Here is the relevant section of the org manual:

3.5.9 Updating the table
------------------------

Recalculation of a table is normally not automatic, but needs to be
triggered by a command.  See *note Advanced features::, for a way to
make recalculation at least semi-automatic.

   In order to recalculate a line of a table or the entire table, use
the following commands:

`C-c *     (`org-table-recalculate')'
     Recalculate the current row by first applying the stored column
     formulas from left to right, and all field/range formulas in the
     current row.  

`C-u C-c *'
`C-u C-c C-c'
     Recompute the entire table, line by line.  Any lines before the
     first hline are left alone, assuming that these are part of the
     table header.  

`C-u C-u C-c *  or  C-u C-u C-c C-c     (`org-table-iterate')'
     Iterate the table by recomputing it until no further changes occur.
     This may be necessary if some computed fields use the value of
     other fields that are computed later in the calculation sequence.

`M-x org-table-recalculate-buffer-tables RET'
     Recompute all tables in the current buffer.

`M-x org-table-iterate-buffer-tables RET'
     Iterate all tables in the current buffer, in order to converge
     table-to-table dependencies.

Edit: With respect to the second issue: multiple TBLFM lines are allowed, but they are for specifying multiple variants of the table formulae. Only the first TBLFM line gets applied automatically, see this section of the manual.

deprecated
  • 2,775
  • 14
  • 15