emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Adonay Felipe Nogueira <adfeno@openmailbox.org>
To: emacs-orgmode@gnu.org
Subject: Re: Calculating percentage
Date: Sat, 15 Jul 2017 11:56:52 -0300	[thread overview]
Message-ID: <87y3rpd9zf.fsf@openmailbox.org> (raw)
In-Reply-To: <CAG-LmmAGPkJBNdwKFxw-z4DxQ+W4wdZysxsGwXx5Sa700wj55w@mail.gmail.com> (Cecil Westerhof's message of "Sat, 15 Jul 2017 07:06:15 +0200")

* If you want to calculate the percentage change

Say, from [last row, first column] to [current row, first column], that
is:

( current - last_in_table ) / last_in_table

Then do either one of the following:

a. Direct answer. Go below the table and insert (without the extra spaces):

   #+TBLFM: @2$2..@>>$2=relch(@>$1, $1) * 100

b. Detailed answer. Go to any place inside the table and press C-c ',
   and insert (without the extra spaces):

    @2$2..@>>$2=relch(@>$1, $1) * 100

    "@" is row specification, "$" is column specification, ".." selects
    a range. Digits after "@" and "$" are absolute references (but as
    far as I can tell, these digits only count after the horizontal
    lines), ">" or "<" after these are relative to the last and first
    (of the entire table, this as far as I can tell also includes rows
    of horizontal lines), respectively.

The advantages of using (b) over (a) are:

- You have a split, friendly --- and probably highlighted --- view of
  what you're doing.

- Multiple formulas can be inserted simply by breaking a line. In the
  case of (a), you would have to manually insert "::" for each new
  formula for a given cell or cell range. Note that inserting multiple
  "#+TBLFM:" in order to apply multiple formulas to the same table at
  once isn't right, only the first "#+TBLFM" is evaluated.

** Example

--8<---------------cut here---------------start------------->8---
|----------+------------|
|  Average | Percentage |
|----------+------------|
| 3.01E+00 | -96.950355 |
| 7.31E+00 | -92.593718 |
|----------+------------|
| 2.72E+01 | -72.441743 |
| 4.09E+01 | -58.561297 |
|----------+------------|
| 6.80E+01 | -31.104357 |
| 7.07E+01 | -28.368794 |
|----------+------------|
| 7.19E+01 | -27.152989 |
| 9.87E+01 |            |
|----------+------------|
#+TBLFM: @2$2..@>>$2=relch(@>$1, $1) * 100
--8<---------------cut here---------------end--------------->8---

* If you want to calculate the percentage of the new value compared to
  the old value

Such as:

current / last_in_table

Then use:

$1 / @>$1

Instead of:

relch(@>$1, $1)

** Example

--8<---------------cut here---------------start------------->8---
|----------+------------|
|  Average | Percentage |
|----------+------------|
| 3.01E+00 |  3.0496454 |
| 7.31E+00 |  7.4062817 |
|----------+------------|
| 2.72E+01 |  27.558257 |
| 4.09E+01 |  41.438703 |
|----------+------------|
| 6.80E+01 |  68.895643 |
| 7.07E+01 |  71.631206 |
|----------+------------|
| 7.19E+01 |  72.847011 |
| 9.87E+01 |            |
|----------+------------|
#+TBLFM: @2$2..@>>$2=($1 / @>$1) * 100
--8<---------------cut here---------------end--------------->8---

-- 
- [[https://libreplanet.org/wiki/User:Adfeno]]
- Palestrante e consultor sobre /software/ livre (não confundir com
  gratis).
- "WhatsApp"? Ele não é livre, por isso não uso. Iguais a ele prefiro
  GNU Ring, ou Tox. Quer outras formas de contato? Adicione o vCard
  que está no endereço acima aos teus contatos.
- Pretende me enviar arquivos .doc, .ppt, .cdr, ou .mp3? OK, eu
  aceito, mas não repasso. Entrego apenas em formatos favoráveis ao
  /software/ livre. Favor entrar em contato em caso de dúvida.

  reply	other threads:[~2017-07-15 15:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-15  5:06 Calculating percentage Cecil Westerhof
2017-07-15 14:56 ` Adonay Felipe Nogueira [this message]
     [not found] <e59c1668074b42d6855ee636cc8ad3ec@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
2017-07-16 18:32 ` Eric S Fraga
2017-07-17  8:22   ` Cecil Westerhof

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=87y3rpd9zf.fsf@openmailbox.org \
    --to=adfeno@openmailbox.org \
    --cc=emacs-orgmode@gnu.org \
    /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).