emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Dokos <nicholas.dokos@hp.com>
To: Rustom Mody <rustompmody@gmail.com>
Cc: nicholas.dokos@hp.com, emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: making flexible table formulas
Date: Tue, 01 Mar 2011 00:10:11 -0500	[thread overview]
Message-ID: <1742.1298956211@alphaville.dokosmarshall.org> (raw)
In-Reply-To: Message from Rustom Mody <rustompmody@gmail.com> of "Tue, 01 Mar 2011 08:49:40 +0530." <AANLkTimkEbZkcWWjHOC4nrWLhj-ZUddROei+O_sJDO+d@mail.gmail.com>

Rustom Mody <rustompmody@gmail.com> wrote:

> Nick Dokos wrote:
> 
> > Of course it's reasonable - and of course, org implements it
> > #+TBLFM: $LR2=vsum(@1..@-1)
> 
> Thanks Nick I can use that. But I dont understand it.  What's the -1?
> The manual says -- relative to 'current' column.
> What determines 'current?' There must be some obvious POV which I am missing...
> 

The formula calculates $LR2: the cell in the last row, column 2.
That's what determines 'current'. Since there is no column spec
on the right-hand side, column 2 is implied. IOW, the formula
is equivalent to this:

#+TBLFM: $LR2=vsum(@1$2..@-1$2)

The vsum on the RHS ranges then from row 1, column 2 (@1$2)
to the row above the last one, still on column 2 (@-1$2).

BTW, if you have a header you should start at row 2 (separator
lines don't count):

|     A |  B |
|-------+----|
|     1 |  1 |
|     2 |  4 |
|     3 |  9 |
| Total | 14 |
#+TBLFM: $LR2=vsum(@2..@-1)

or use the alternative syntax that Luke Crook suggested [fn:1]

#+TBLFM: $LR2=vsum(@I..@-1)

which goes from the first separator (@I) to the penultimate row
(@-1) - and remember that separator lines are ignored in the
calculation.

HTH, [fn:2]
Nick

Footnotes:
[fn:1] Luke suggested the following formula:

#+TBLFM: @8$2=vsum(@I..@II)

with the assumption that there will be two separator lines,
one after the header and one just before the last row,
in effect demarcating the useful part of the table:


|     A |  B |
|-------+----|
|     1 |  1 |
|     2 |  4 |
|     3 |  9 |
|-------+----|
| Total | 14 |
#+TBLFM: $LR2=vsum(@I..@II)

[Luke's LHS fixes the row to 8 which is not correct - I corrected
that in the above formula.]

The only problem with this is if you decide to insert more separators in
the table or you don't want separators at all; but assuming that you can
live with the two (and only those two), it's a good solution.

[fn:2] BTW, you can turn on formula debugging from the Tbl menu or with C-c {
and see what it is calculating: I used a slighty different table - added a few 
more rows with S-RET in column 1 and I also had a formula to calculate
the squares in column 2, so the table looked like this:

|     a | b |
|-------+---|
|     1 |   |
|     2 |   |
|     3 |   |
|     4 |   |
|     5 |   |
|     6 |   |
|-------+---|
| Total |   |

#+TBLFM: $LR2=vsum(@2..@-1)::$2 = pow($1, 2)

Then pressing C-c C-c on the #+TBLFM line and saying yes a few times,
you finally get this 

|     a |  b |
|-------+----|
|     1 |  1 |
|     2 |  4 |
|     3 |  9 |
|     4 | 16 |
|     5 | 25 |
|     6 | 36 |
|-------+----|
| Total | 91 |

#+TBLFM: $LR2 = vsum(@2..@-1)::$2 = pow($1, 2)

with the following in the formula debugging buffer:

,----
| Substitution history of formula
| Orig:   vsum(@2..@-1)
| $xyz->  vsum(@2..@-1)
| @r$c->  vsum([1,4,9,16,25,36])
| $1->    vsum([1,4,9,16,25,36])
| Result: 91
| Format: NONE
| Final:  91
`----

  parent reply	other threads:[~2011-03-01  5:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-01  3:19 making flexible table formulas Rustom Mody
2011-03-01  4:41 ` theo
2011-03-01  5:10 ` Nick Dokos [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-02-28 17:35 Rustom Mody
2011-02-28 18:14 ` Luke Crook
2011-02-28 18:18 ` Nick Dokos
2011-03-01  9:08 ` Carsten Dominik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1742.1298956211@alphaville.dokosmarshall.org \
    --to=nicholas.dokos@hp.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=rustompmody@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).