emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Table calculation question
@ 2007-08-26 19:39 Bernt Hansen
  2007-08-27  1:44 ` Eddward DeVilla
  2007-08-27  2:25 ` Carsten Dominik
  0 siblings, 2 replies; 4+ messages in thread
From: Bernt Hansen @ 2007-08-26 19:39 UTC (permalink / raw)
  To: emacs-orgmode

In the following table I'd like to vertically sum the column and the
compute a new value based on that sum.

|---+---+---+---+-------+---------|
|   | A | B | C | Total | Details |
|---+---+---+---+-------+---------|
| # | 1 | 2 | 4 |     7 | Item 1  |
| # | 2 | 6 | 4 |    12 | Item 2  |
| # | 2 | 4 | 4 |    10 | Item 3  |
| # | 2 | 6 | 3 |    11 | Item 4  |
|---+---+---+---+-------+---------|
| # |   |   |   |    40 | 400.00  |
| ^ |   |   |   |   tot | result  |
| $ |   |   |   |       | kval=10 |
|---+---+---+---+-------+---------|
#+TBLFM: $5=$2+$3+$4::$tot=vsum(@-II..@-I)::$result=$tot*$kval;%.2f

If I edit any of the values in columns A, B, C and do C-u C-c C-c then
the total (tot) value is recalculated but result is not.  Doing C-u C-c
C-c a second time recalculates result based on the new tot value.

Is there a way to do this in a single table recalculation?

Thanks,
Bernt

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Table calculation question
  2007-08-26 19:39 Table calculation question Bernt Hansen
@ 2007-08-27  1:44 ` Eddward DeVilla
  2007-08-27  2:25 ` Carsten Dominik
  1 sibling, 0 replies; 4+ messages in thread
From: Eddward DeVilla @ 2007-08-27  1:44 UTC (permalink / raw)
  To: Bernt Hansen; +Cc: emacs-orgmode

On 8/26/07, Bernt Hansen <bernt@alumni.uwaterloo.ca> wrote:
> In the following table I'd like to vertically sum the column and the
> compute a new value based on that sum.
>
> |---+---+---+---+-------+---------|
> |   | A | B | C | Total | Details |
> |---+---+---+---+-------+---------|
> | # | 1 | 2 | 4 |     7 | Item 1  |
> | # | 2 | 6 | 4 |    12 | Item 2  |
> | # | 2 | 4 | 4 |    10 | Item 3  |
> | # | 2 | 6 | 3 |    11 | Item 4  |
> |---+---+---+---+-------+---------|
> | # |   |   |   |    40 | 400.00  |
> | ^ |   |   |   |   tot | result  |
> | $ |   |   |   |       | kval=10 |
> |---+---+---+---+-------+---------|
> #+TBLFM: $5=$2+$3+$4::$tot=vsum(@-II..@-I)::$result=$tot*$kval;%.2f
>
> If I edit any of the values in columns A, B, C and do C-u C-c C-c then
> the total (tot) value is recalculated but result is not.  Doing C-u C-c
> C-c a second time recalculates result based on the new tot value.
>
> Is there a way to do this in a single table recalculation?
>
> Thanks,
> Bernt

I have this in some of my tables.  Right now I just live with it.  The
problem is you can't really have computed value dependent on other
computed values.  Either you can do I like I do when I feel lazy and
recalculate until things stabilize or you can rewrite your formulas to
not depend on other computed values.  So in the case of tot, use tot =
vsum(@-II$2..@-I$5) or something like that.  (I don't have calc so I
can't test this.)

For now, I wish the table editor would highlight calculated cells or
do something to let you know when you are calculating one field using
another calculated field.  I've been telling myself that I'm going to
dig into the formula evaluator and see if I can't get it to inline
formulas from other referenced cells so it will 'do the right thing'.
I'm sure it not trivial and for now there is a work around.

Edd

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Table calculation question
  2007-08-26 19:39 Table calculation question Bernt Hansen
  2007-08-27  1:44 ` Eddward DeVilla
@ 2007-08-27  2:25 ` Carsten Dominik
  2007-08-27  2:33   ` Bernt Hansen
  1 sibling, 1 reply; 4+ messages in thread
From: Carsten Dominik @ 2007-08-27  2:25 UTC (permalink / raw)
  To: Bernt Hansen; +Cc: emacs-orgmode


On Aug 26, 2007, at 21:39, Bernt Hansen wrote:

> In the following table I'd like to vertically sum the column and the
> compute a new value based on that sum.
>
> |---+---+---+---+-------+---------|
> |   | A | B | C | Total | Details |
> |---+---+---+---+-------+---------|
> | # | 1 | 2 | 4 |     7 | Item 1  |
> | # | 2 | 6 | 4 |    12 | Item 2  |
> | # | 2 | 4 | 4 |    10 | Item 3  |
> | # | 2 | 6 | 3 |    11 | Item 4  |
> |---+---+---+---+-------+---------|
> | # |   |   |   |    40 | 400.00  |
> | ^ |   |   |   |   tot | result  |
> | $ |   |   |   |       | kval=10 |
> |---+---+---+---+-------+---------|
> #+TBLFM: $5=$2+$3+$4::$tot=vsum(@-II..@-I)::$result=$tot*$kval;%.2f
>
> If I edit any of the values in columns A, B, C and do C-u C-c C-c then
> the total (tot) value is recalculated but result is not.  Doing C-u C-c
> C-c a second time recalculates result based on the new tot value.
>
> Is there a way to do this in a single table recalculation?

`C-u C-u C-c C-c' iterates a table until it is stable and in this way
takes care of formulas depending on calculated fields.

If you want to do this all the time you can do something like

(add-hook 'org-mode-hook
   (lambda () (local-set-key [f5]
                (lambda () (interactive) (org-table-recalculate 
'(16))))))

- Carsten

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Table calculation question
  2007-08-27  2:25 ` Carsten Dominik
@ 2007-08-27  2:33   ` Bernt Hansen
  0 siblings, 0 replies; 4+ messages in thread
From: Bernt Hansen @ 2007-08-27  2:33 UTC (permalink / raw)
  To: emacs-orgmode

Carsten Dominik <dominik@science.uva.nl> writes:

> `C-u C-u C-c C-c' iterates a table until it is stable and in this way
> takes care of formulas depending on calculated fields.

Thanks Carsten!  I wasn't aware of that feature :)

Regards,
Bernt

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-08-27  2:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-26 19:39 Table calculation question Bernt Hansen
2007-08-27  1:44 ` Eddward DeVilla
2007-08-27  2:25 ` Carsten Dominik
2007-08-27  2:33   ` Bernt Hansen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).