emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* table, calc, reorder and protect calculation in one cell
@ 2019-06-11  9:35 Uwe Brauer
  2019-06-17  6:07 ` Michael Brand
  0 siblings, 1 reply; 4+ messages in thread
From: Uwe Brauer @ 2019-06-11  9:35 UTC (permalink / raw)
  To: emacs-orgmode

Hi

I have the following problem

This is my original table

The row starting with smith is calculated differently from the other two

* Orginal

#+begin_src 
| name   | C1 | C2 | Res |
|--------+----+----+-----|
| Adams  |  5 |  5 |  10 |
| Miller |  6 |  2 |   8 |
| Smith  |  9 |  1 | 1.7 |
,#+TBLFM: $4=$3+$2::@4$4=0.1*@4$2+0.8*@4$3
#+end_src

Now I reorder the table using the column C1
* Original reordered
#+begin_src 
| name   | C1 | C2 | Res |
|--------+----+----+-----|
| Smith  |  9 |  1 |  10 |
| Miller |  6 |  2 |   8 |
| Adams  |  5 |  5 | 4.5 |
,#+TBLFM: $4=$3+$2::@4$4=0.1*@4$2+0.8*@4$3
#+end_src


Everything looks fine, however when I recalculate the table calc follows
its definition and I obtain 
* Original reordered recalculated

#+begin_src 
| name   | C1 | C2 | Res |
|--------+----+----+-----|
| Smith  |  9 |  1 |  10 |
| Miller |  6 |  2 |   8 |
| Adams  |  5 |  5 | 4.5 |
,#+TBLFM: $4=$3+$2::@4$4=0.1*@4$2+0.8*@4$3
#+end_src

Which is not what I want. So the question is this.
Is there any way to enhance the ordering of rows so that it is reflected
in the way the rows a calculated
I mean reordering should/could have produced

* Original reordered TBLFM changed

#+begin_src 
| name   | C1 | C2 | Res |
|--------+----+----+-----|
| Smith  |  9 |  1 |  10 |
| Miller |  6 |  2 |   8 |
| Adams  |  5 |  5 | 4.5 |
,#+TBLFM: $4=$3+$2::@2$4=0.1*@2$2+0.8*@2$3
#+end_src


Is this behavior possible? When I delete a row or a column, the  TBLFM
is updated, could that be done for reordering?

Thanks 

Uwe Brauer 

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

* Re: table, calc, reorder and protect calculation in one cell
  2019-06-11  9:35 table, calc, reorder and protect calculation in one cell Uwe Brauer
@ 2019-06-17  6:07 ` Michael Brand
  2019-06-17 21:06   ` Uwe Brauer
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Brand @ 2019-06-17  6:07 UTC (permalink / raw)
  To: Org Mode

Hi Uwe

On Tue, Jun 11, 2019 at 11:36 AM Uwe Brauer <oub@mat.ucm.es> wrote:

> Is this behavior possible? When I delete a row or a column, the  TBLFM
> is updated, could that be done for reordering?

You may want to use something like this, (I knew the syntax for ~"$1"~
and used the formula debugger ~C-c {~ to find the syntax for
~"(Smith)"~):

| name   | C1 | C2 | Res |
|--------+----+----+-----|
| Smith  |  9 |  1 | 1.7 |
| Miller |  6 |  2 |   8 |
| Adams  |  5 |  5 |  10 |
#+TBLFM: $4 = if("$1" == "(Smith)", 0.1 * $2 + 0.8 * $3, $3 + $2)

Michael

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

* Re: table, calc, reorder and protect calculation in one cell
  2019-06-17  6:07 ` Michael Brand
@ 2019-06-17 21:06   ` Uwe Brauer
  2019-08-10 14:09     ` Carsten Dominik
  0 siblings, 1 reply; 4+ messages in thread
From: Uwe Brauer @ 2019-06-17 21:06 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 846 bytes --]

>>> "MB" == Michael Brand <michael.ch.brand@gmail.com> writes:

> Hi Uwe
> On Tue, Jun 11, 2019 at 11:36 AM Uwe Brauer <oub@mat.ucm.es> wrote:

>> Is this behavior possible? When I delete a row or a column, the  TBLFM
>> is updated, could that be done for reordering?

> You may want to use something like this, (I knew the syntax for ~"$1"~
> and used the formula debugger ~C-c {~ to find the syntax for
> ~"(Smith)"~):

> | name   | C1 | C2 | Res |
> |--------+----+----+-----|
> | Smith  |  9 |  1 | 1.7 |
> | Miller |  6 |  2 |   8 |
> | Adams  |  5 |  5 |  10 |

> #+TBLFM: $4 = if("$1" == "(Smith)", 0.1 * $2 + 0.8 * $3, $3 + $2)

Ha, of course, thanks, why did that occur to me? I am bit surprised by
the () in Smith, should "Smith" not be sufficient? But it is not indeed,
how odd?

Anyhow, thanks a lot.

Uwe 

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5025 bytes --]

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

* Re: table, calc, reorder and protect calculation in one cell
  2019-06-17 21:06   ` Uwe Brauer
@ 2019-08-10 14:09     ` Carsten Dominik
  0 siblings, 0 replies; 4+ messages in thread
From: Carsten Dominik @ 2019-08-10 14:09 UTC (permalink / raw)
  To: org-mode list

[-- Attachment #1: Type: text/plain, Size: 1835 bytes --]

On Mon, Jun 17, 2019 at 11:08 PM Uwe Brauer <oub@mat.ucm.es> wrote:

> >>> "MB" == Michael Brand <michael.ch.brand@gmail.com> writes:
>
> > Hi Uwe
> > On Tue, Jun 11, 2019 at 11:36 AM Uwe Brauer <oub@mat.ucm.es> wrote:
>
> >> Is this behavior possible? When I delete a row or a column, the  TBLFM
> >> is updated, could that be done for reordering?
>
> > You may want to use something like this, (I knew the syntax for ~"$1"~
> > and used the formula debugger ~C-c {~ to find the syntax for
> > ~"(Smith)"~):
>
> > | name   | C1 | C2 | Res |
> > |--------+----+----+-----|
> > | Smith  |  9 |  1 | 1.7 |
> > | Miller |  6 |  2 |   8 |
> > | Adams  |  5 |  5 |  10 |
>
> > #+TBLFM: $4 = if("$1" == "(Smith)", 0.1 * $2 + 0.8 * $3, $3 + $2)
>
> Ha, of course, thanks, why did that occur to me? I am bit surprised by
> the () in Smith, should "Smith" not be sufficient? But it is not indeed,
> how odd?
>

Indeed, this looks very weird.  It has to do with the fact that table
formulas usually deal with numbers and expressions and not with strings.
When replacing $1 in a calc formula, Org adds parenthesis to allow also
algebraic expressions in such formulas.  Consider the following case:

| 2 | 2+3 | 10 |
#+TBLFM: $3=$1*$2

This formula needs to be interpreted as 2 * (2+3).  Without the
parenthesis, it would be read as 2*2+3, which is 7, not 10.
Basically, we need to make sure that whatever is in the field is
interpreted as one entity and not ripped apart by the operator precedence
in calc.  And therefore, indeed, if you want to compare strings, you need
to add the odd-looking parenthesis inside the double quotes.

I guess we should document this.  For lisp formulas, I did document the
variable interpolation, but apparently not for calc syntax.
I will put this into the manual.

Carsten


>
> Anyhow, thanks a lot.
>
> Uwe
>

[-- Attachment #2: Type: text/html, Size: 2777 bytes --]

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

end of thread, other threads:[~2019-08-10 14:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-11  9:35 table, calc, reorder and protect calculation in one cell Uwe Brauer
2019-06-17  6:07 ` Michael Brand
2019-06-17 21:06   ` Uwe Brauer
2019-08-10 14:09     ` Carsten Dominik

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).