emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Bastien <bzg@gnu.org>
To: "Oliver Večerník" <ov@vecernik.at>
Cc: emacs-orgmode@gnu.org
Subject: Re: Spreadsheet calculations (24.3/8.0-pre)
Date: Thu, 18 Apr 2013 16:13:11 +0200	[thread overview]
Message-ID: <8761zk2ah4.fsf@bzg.ath.cx> (raw)
In-Reply-To: <871ualhzyu.fsf@kerstf.org> ("Oliver Večerník"'s message of "Mon, 08 Apr 2013 16:14:01 +0200")

Hi Oliver,

Oliver Večerník <ov@vecernik.at> writes:

> Hi Ippei,
>
>> | Product   |    g | kJ/100g |   kJ | kcal |
>> |-----------+------+---------+------+------|
>> | Bread     | 50.6 |    1372 |  694 |  166 |
>> | Butter    | 11.5 |    3054 |  351 |   84 |
>> | Marmalade | 19.7 |     926 |  182 |   44 |
>> |-----------+------+---------+------+------|
>> |           |      |         | 1227 |  294 |
>> #+TBLFM: $3='(org-lookup-first $1 '(remote(nf,@I$1..@II$1))
>> (remote(nf,@I$2..@II$2)))
>> #+TBLFM: $4='(* $2 (/ $3 $b));N%.0f
>> #+TBLFM: $5=$4/$j;%.0f
>> #+TBLFM: @>$4..$5=vsum(@I..II)
>> (Each TBLFM line has no linebreak.)
>
> thanks for your suggestion, but I didn't want an extra column.  I played
> with `N' and `L' options and found following solution leaving them
> out entirely:
>
> #+TITLE: Nutrition Facts
> #+CONSTANTS: b=100.0 j=4.184
> #+TBLNAME: nf
> | Product     |   kJ | kcal |
> |-------------+------+------|
> | Bread white | 1372 |  328 |
> | Butter      | 3054 |  730 |
> | Marmalade   |  926 |  221 |
> #+TBLFM: $3=$2/$j;%.0f
>
> | Product     |    g |   kJ | kcal |
> |-------------+------+------+------|
> | Bread white | 50.6 |  694 |  166 |
> | Butter      | 11.5 |  351 |   84 |
> | Marmalade   | 19.7 |  182 |   43 |
> | nonexistent |      |    0 |    0 |
> |-------------+------+------+------|
> |             |      | 1227 |  293 |
> #+TBLFM: $3='(* (string-to-number $2) (/ (string-to-number (org-lookup-last $1 '(remote(nf,@I$1..@II$1)) '(remote(nf,@I$2..@II$2)))) $b));%.0f::$4=$3/$j;%.0f::@>$3..$4=vsum(@I..II)
>
> $1 has to be a string, because the lookup column can have more than one
> word.  For the math I have to convert the strings to numbers.  Maybe
> someone has an idea for a more elegant solution, but this works for
> me now.

I confirm there is no other elegant solution that either using an
additional column or using the internal conversion you used.  

-- 
 Bastien

      reply	other threads:[~2013-04-18 14:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-18  9:52 Spreadsheet calculations (24.3/8.0-pre) Oliver Večerník
2013-03-18 15:03 ` Christopher Allan Webber
2013-03-19 14:27 ` Bastien
2013-03-20  5:48   ` Oliver Večerník
2013-04-07  9:53     ` Ippei FURUHASHI
2013-04-08 14:14       ` Oliver Večerník
2013-04-18 14:13         ` Bastien [this message]

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=8761zk2ah4.fsf@bzg.ath.cx \
    --to=bzg@gnu.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=ov@vecernik.at \
    /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).