From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: table spreadsheet problem Date: Mon, 19 Mar 2012 11:56:48 -0400 Message-ID: <17453.1332172608@alphaville> References: <20120319153221.GN31713@x201> Reply-To: nicholas.dokos@hp.com Return-path: Received: from eggs.gnu.org ([208.118.235.92]:35848) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9exL-00084e-KE for emacs-orgmode@gnu.org; Mon, 19 Mar 2012 11:57:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S9exE-0002ob-SC for emacs-orgmode@gnu.org; Mon, 19 Mar 2012 11:57:11 -0400 Received: from g1t0026.austin.hp.com ([15.216.28.33]:38661) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9exE-0002jO-Kj for emacs-orgmode@gnu.org; Mon, 19 Mar 2012 11:57:04 -0400 Received: from g1t0039.austin.hp.com (g1t0039.austin.hp.com [16.236.32.45]) by g1t0026.austin.hp.com (Postfix) with ESMTP id 63330C0ED for ; Mon, 19 Mar 2012 15:56:51 +0000 (UTC) In-Reply-To: Message from Russell Adams of "Mon, 19 Mar 2012 10:32:21 CDT." <20120319153221.GN31713@x201> 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: emacs-orgmode@gnu.org Cc: nicholas.dokos@hp.com Russell Adams wrote: > On Mon, Mar 19, 2012 at 04:01:42PM +0100, Martin Halder wrote: > > Hi all, > > > > question about table calculation. Found in the documentation that I could refer to e.g. first line after second hline with @II+2. > > > > Would like to calculate sum = vsum(@I..@II) and tax = sum * 0.08 > > > > Am I doing sth wrong ? > > > > Thanks for help, > > Martin > > > > | article | price | > > |---------+--------| > > | item1 | 100.00 | > > | item2 | 200.00 | > > |---------+--------| > > | sum | | > > | tax | | > > |---------+--------| > > | sum | 0 | > > #+TBLFM: @II+1$2=vsum(@I..@II);f2N::@II+2$2=@II+1$2*0.08;f2N::@>$2=vsum(@II..@III);f2N > > > > > > | article | price | > |---------+--------| > | item1 | 100.00 | > | item2 | 200.00 | > |---------+--------| > | sum | 300.00 | > | tax | 24.00 | > |---------+--------| > | sum | 324.00 | > #+TBLFM: @4$2=vsum(@-I..@-II);%.2f::@5$2=@4$2*0.08;%.2f::@6$2=vsum(@-I..@-II);%.2f > > I often use negative headline references for total lines in order to > sum backward from the current cell. > > So vsum(@-I..@-II);%.2f means sum the cells between the first headline > above the current cell to the second headline above the current cell, > and then format the result as a decimal with two decimal places > (%.2f). > > Looking at your formula, I think you manually wrote the TBLFM > line. One thing I've found is that the TBLFM line doesn't support > relative references for the cell specification, only in the formula. > > I used C-u C-c = to set mine. > Nowadays, you can use (both on the LHS and the RHS of the formula) symbolic references relative to the first, second, third ... row like this: @<, @<<, @<< ... and relative to the last, penultimate, antepenultimate (is there such a word?) row like this: @>, @>>, @>>> ..., and similarly for columns, so you could write the formula, like this: #+TBLFM: @>>>$>=vsum(@-I..@-II);%.2f::@>>$>=@>>>$>*0.08;%.2f::@>$>=vsum(@-I..@-II);%.2f This *does* require iterated evaluations, so C-u C-u C-c C-c is your best bet, to make sure everything is updated properly. Nick > Good luck! > > ------------------------------------------------------------------ > Russell Adams RLAdams@AdamsInfoServ.com > > PGP Key ID: 0x1160DCB3 http://www.adamsinfoserv.com/ > > Fingerprint: 1723 D8CA 4280 1EC9 557F 66E8 1154 E018 1160 DCB3 >