From mboxrd@z Thu Jan 1 00:00:00 1970 From: Guido Van Hoecke Subject: Re: Using constants in columns Date: Fri, 16 Oct 2015 16:38:14 +0200 Message-ID: References: <877fmmsz49.fsf@ucl.ac.uk> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=e89a8f83a2e7a2580f052239c04c Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:48389) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn69d-0007gv-Tm for emacs-orgmode@gnu.org; Fri, 16 Oct 2015 10:38:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zn69c-00040C-Pt for emacs-orgmode@gnu.org; Fri, 16 Oct 2015 10:38:45 -0400 Received: from mail-wi0-x230.google.com ([2a00:1450:400c:c05::230]:33375) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zn69c-000407-GK for emacs-orgmode@gnu.org; Fri, 16 Oct 2015 10:38:44 -0400 Received: by wijp11 with SMTP id p11so13694207wij.0 for ; Fri, 16 Oct 2015 07:38:43 -0700 (PDT) In-Reply-To: <877fmmsz49.fsf@ucl.ac.uk> 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: orgmode , Eric S Fraga --e89a8f83a2e7a2580f052239c04c Content-Type: text/plain; charset=UTF-8 Hi Eric, Thanks for the suggestions, I'll go for the integer value used as an index :) Have a nice weekend, Guido On 16 October 2015 at 15:48, Eric S Fraga wrote: > On Friday, 16 Oct 2015 at 14:39, Guido Van Hoecke wrote: > > Hi, > > > > Is there a way to use a constant directly in a table column? > > I need to have a table where one of the columns can have one out of three > > possible values and wanted to use constants for this. > > From the following minimal example it appears that constants are only > > possible in formulas, or am I missing something? > > > > #+CONSTANTS: vat=1.21 > > | 12.34 | $vat | #ERROR | 14.9314 | > > > > #+TBLFM: $3=$1*$2::$4=$1*$vat > > > > Using the $vat constant directly from the content of column 3 produces an > > error, using it from a formula works fine. > > > > If this is the way it is, I'll have to write a formula for each row of > the > > column, that'd be a real pitty... > > Maybe not pretty but for a small number of alternatives, you could do: > > #+begin_src org > ,#+constants: vat=[1.15,1.21,1.40] > | amount | vat1 | vat2 | vat3 | total | > |--------+------+------+------+---------| > | 12.34 | 1 | 0 | 0 | 14.191 | > | 56.78 | 0 | 1 | 0 | 68.7038 | > ,#+TBLFM: $5=$1*vsum($2..$4*$vat) > #+end_src > > alternatively, you could have an integer value in the VAT column and use > that to index the vector of VAT values? > -- > : Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.2, Org release_8.3.2-161-gd2ac25 > --e89a8f83a2e7a2580f052239c04c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi Eric,

Thanks for the suggestions, I&= #39;ll go for the integer value used as an index :)

Have a = nice weekend,


Guido

On 16 October 2015 at 15:48, Eric S F= raga <e.fraga@ucl.ac.uk> wrote:
On Friday, 16 Oct 2015 at 14:39, Guido Van Hoecke wr= ote:
> Hi,
>
> Is there a way to use a constant directly in a table column?
> I need to have a table where one of the columns can have one out of th= ree
> possible values and wanted to use constants for this.
> From the following minimal example it appears that constants are only<= br> > possible in formulas, or am I missing something?
>
> #+CONSTANTS: vat=3D1.21
> | 12.34 | $vat | #ERROR | 14.9314 |
>
> #+TBLFM: $3=3D$1*$2::$4=3D$1*$vat
>
> Using the $vat constant directly from the content of column 3 produces= an
> error, using it from a formula works fine.
>
> If this is the way it is, I'll have to write a formula for each ro= w of the
> column, that'd be a real pitty...

Maybe not pretty but for a small number of alternatives, you could d= o:

#+begin_src org
=C2=A0 ,#+constants: vat=3D[1.15,1.21,1.40]
=C2=A0 | amount | vat1 | vat2 | vat3 |=C2=A0 =C2=A0total |
=C2=A0 |--------+------+------+------+---------|
=C2=A0 |=C2=A0 12.34 |=C2=A0 =C2=A0 1 |=C2=A0 =C2=A0 0 |=C2=A0 =C2=A0 0 |= =C2=A0 14.191 |
=C2=A0 |=C2=A0 56.78 |=C2=A0 =C2=A0 0 |=C2=A0 =C2=A0 1 |=C2=A0 =C2=A0 0 | 6= 8.7038 |
=C2=A0 ,#+TBLFM: $5=3D$1*vsum($2..$4*$vat)
#+end_src

alternatively, you could have an integer value in the VAT column and use that to index the vector of VAT values?
--
: Eric S Fraga (0xFFFCF67D), Emacs 25.0.50.2, Org release_8.3.2-161-gd2ac25=

--e89a8f83a2e7a2580f052239c04c--