From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christopher Allan Webber Subject: Re: Spreadsheet calculations (24.3/8.0-pre) Date: Mon, 18 Mar 2013 10:03:48 -0500 Message-ID: <87li9k3g3d.fsf@earlgrey.lan> References: <87li9lm3vj.fsf@kerstf.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:35659) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHbb9-0001Pq-8P for emacs-orgmode@gnu.org; Mon, 18 Mar 2013 11:03:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UHbb2-00065X-EA for emacs-orgmode@gnu.org; Mon, 18 Mar 2013 11:03:39 -0400 Received: from li424-160.members.linode.com ([50.116.34.160]:39797 helo=dustycloud.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UHbb2-00064c-8j for emacs-orgmode@gnu.org; Mon, 18 Mar 2013 11:03:32 -0400 In-reply-to: <87li9lm3vj.fsf@kerstf.org> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: =?utf-8?Q?Oliver_Ve=C4=8Dern=C3=ADk?= Cc: emacs-orgmode@gnu.org I've posted here before about it, but it looks like you're trying to do the same thing as I am; see https://gitorious.org/org-diet Here's an example of an org-diet file entry: | Food / Exercise | Calories | Quantity | Total | |----------------------------------------+----------+----------+-------| | thin & crispy flatbread | 16 | 2 | 32 | | tbsp neufchatel cheese spread | 35 | 1 | 35 | | tbsp apple butter | 30 | .5 | 15 | | tbsp jam | 50 | .5 | 25 | | Tea w/ agave & creamer | 40 | 1 | 40 | | cedarlane eggplant parmesan | 240 | 1 | 240 | | goldfish cracker | 2 | 20 | 40 | | bequet wrapped caramel | 48 | 1 | 48 | | Beverage w/ sugar in the raw & creamer | 40 | 1 | 40 | | pecan half | 10 | 3 | 30 | | orange | 62 | 1 | 62 | | presliced aged swiss cheese | 70 | 1 | 70 | | starbucks tall latte low fat milk | 109 | 1 | 109 | | 1 pkt sugar in the raw | 20 | 1 | 20 | | amy's cheese lasagna | 380 | 1 | 380 | | baby carrot | 4 | 3 | 12 | | cup low fat cottage cheese | 180 | .5 | 90 | | tofutti cutie | 130 | 1 | 130 | |----------------------------------------+----------+----------+-------| | Total | | | 1418 | #+TBLFM: $4=3D$2*$3;%.0f::$LR4=3Dvsum(@2$4..@-I$4) That's not answering your question but might be useful given the type of things you appear to be entering :) Oliver Ve=C4=8Dern=C3=ADk writes: > Hi, > > I'm trying to do some simple calculations, but the results are plain > wrong. I started the minimal example with `emacs -Q -l minimal.emacs > org/minimal.org'. My Emacs is 24.3 with Org-mode version 8.0-pre > (release_8.0-pre-116-g65cde8 @ /home/ov/p/org-mode/lisp/): > > #+TITLE: Nutrition Facts > #+CONSTANTS: b=3D100 j=3D4.182 > > #+TBLNAME: nf > | Product | kJ | kcal | > |-----------+------+------| > | Bread | 1372 | 328 | > | Butter | 3054 | 730 | > | Marmalade | 926 | 221 | > #+TBLFM: $3=3D$2/$j;%.0f > > Here are some calculations per portion (plain wrong): > > | Product | g | kJ | kcal | > |-----------+------+------+------| > | Bread | 50.6 | 658 | 157 | > | Butter | 11.5 | 150 | 36 | > | Marmalade | 19.7 | 256 | 61 | > |-----------+------+------+------| > | | | 1064 | 254 | > #+TBLFM: $3=3D'(* $2 (/ (org-lookup-first $1 '(remote(nf,@I$1..@II$1)) = '(remote(nf,@I$2..@II$2))) 100));N%.0f::$4=3D$3/$j;%.0f::@>$3..$4=3Dvsum(= @I..II) > > Expected: > > | Product | g | kJ | kcal | > |-----------+------+------+------| > | Bread | 50.6 | 694 | 166 | > | Butter | 11.5 | 351 | 84 | > | Marmalade | 19.7 | 182 | 44 | > |-----------+------+------+------| > | | | 1227 | 294 | > #+TBLFM: $4=3D$3/$j;%.0f::@>$3..$4=3Dvsum(@I..II) > > Using the constant b is also totally wrong: > > | Product | g | kJ | kcal | > |-----------+------+----+------| > | Bread | 50.6 | 0 | 0 | > | Butter | 11.5 | 0 | 0 | > | Marmalade | 19.7 | 0 | 0 | > |-----------+------+----+------| > | | | 0 | 0 | > #+TBLFM: $3=3D'(* $2 (/ (org-lookup-first $1 '(remote(nf,@I$1..@II$1)) = '(remote(nf,@I$2..@II$2))) $b));N%.0f::$4=3D$3/$j;%.0f::@>$3..$4=3Dvsum(@= I..II) > > These results are achieved using `C-c C-c' on the first column of the > format line. If I use `C-u C-c C-c' in the tabel I get different > results *every* time. E.g. pressing `C-u C-c C-c' three times on the > `B' of `Bread': > > | Product | g | kJ | kcal | > |-----------+------+--------+-------| > | Bread | 50.6 | 32606 | 7784 | > | Butter | 11.5 | 59888 | 14297 | > | Marmalade | 19.7 | 110192 | 26306 | > |-----------+------+--------+-------| > | | | 202686 | 48387 | > #+TBLFM: $3=3D'(* $2 (/ (org-lookup-first $1 '(remote(nf,@I$1..@II$1)) = '(remote(nf,@I$2..@II$2))) 100));N%.0f::$4=3D$3/$j;%.0f::@>$3..$4=3Dvsum(= @I..II) > > If I go to the end of the format line and press `C-c C-c' I get totally > different results as at the beginning: > > | Product | g | 1064 | 254 | > |-----------+------+------+------| > | Bread | 50.6 | 1064 | 254 | > | Butter | 11.5 | 1470 | 351 | > | Marmalade | 19.7 | 2790 | 666 | > |-----------+------+------+------| > | | | 5324 | 1271 | > #+TBLFM: $3=3D'(* $2 (/ (org-lookup-first $1 '(remote(nf,@I$1..@II$1)) = '(remote(nf,@I$2..@II$2))) 100));N%.0f::$4=3D$3/$j;%.0f::@>$3..$4=3Dvsum(= @I..II) > > If I use `M-x org-table-recalculate-buffer-tables' even the headlines > get screwed up. Am I doing something wrong or are there severe problem= s > in the spreadsheet mode? > > Thanks in advance!