NightLearner
NightLearner

Reputation: 305

Storing and Calling Expressions with IronPython in Spotfire

Is there anyway to store an expression in an IronPython script in Spotfire, and then call on it later to simplify my scripts where I am adding a bunch of calculated columns? Some of my expressions are simply (A+B), but i am also trying to see if it is possible to store an if then "case statement" as an expression

For example:

expression1 = [VarA] * 3.289

expression2 ~ (VarA] / [VarB]) * 23.33

expression3 = Case When [VarA] = 1 Then "Blue" Else "Red" End


example script (this works):

from Spotfire.Dxp.Data import CalculatedColumn
cols = Document.Data.Tables["MyTable"].Columns
cols.AddCalculatedColumn("NewColumn1","[VarA] * 3.289");

Example of what I'd like to do:

from Spotfire.Dxp.Data import CalculatedColumn
cols = Document.Data.Tables["MyTable"].Columns
cols.AddCalculatedColumn("NewColumn1","expression1");
cols.AddCalculatedColumn("NewColumn2","expression2");
cols.AddCalculatedColumn("NewColumn3","expression3");

Upvotes: 2

Views: 762

Answers (1)

End3r117
End3r117

Reputation: 57

I mean maybe I'm not understanding you but I think just make expression1 a variable like you were trying to do. Make sure you use quotation marks for strings and don't use them for variables.

expression1 = "[varA]*3.289"
cols.AddCalculatedColumn("NewColumn1",expression1)

Upvotes: 1

Related Questions