Subscribe Bookmark RSS Feed

How to fix a variable in a column formula

guillaume

Community Member

Joined:

Jun 9, 2015

Hi,

thanks to a script, I want to create a column with a formula which contain a variable as follow:

 

dt=current data table();

variable1=10;

dt<<new column("exemple", numeric, continu, formula(:othercolumn*variable1));

I would like this result in the column formula:

:othercolumn*10

But, I have :othercolumn*variable1.

Any idea of how to fixe the variable?

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

Formula() does not evaluate its argument expression (which makes sense); the expression is just passed on to the data table and evaluated there. Thus the variable must be evaluated before creating the column. Below is one way to do it  (see other approaches in earlier as I'm sure this issue has been up before).

Eval(Eval Expr(dt << New Column("exemple", numeric, formula(:othercolumn * Expr(variable1)))));

1 REPLY
Solution

Formula() does not evaluate its argument expression (which makes sense); the expression is just passed on to the data table and evaluated there. Thus the variable must be evaluated before creating the column. Below is one way to do it  (see other approaches in earlier as I'm sure this issue has been up before).

Eval(Eval Expr(dt << New Column("exemple", numeric, formula(:othercolumn * Expr(variable1)))));