Insert a Calculated Column

from Spotfire.Dxp.Data import CalculatedColumn

newColName = "test"
newColExpr = "TRIM([myTableCol])"

cc = Document.Data.Tables["myTable"].Columns.AddCalculatedColumn(newColName,newColExpr).As[CalculatedColumn]()

#change expression
cc.Expression = "Avg([myTableCol])"


#get calc column and change its expression
cc = Document.Data.Tables["myTable"].Columns["myCalcColumn"].As[CalculatedColumn]()
cc.Expression = "Avg([myTableCol])"


4 comments:

Walktheway said...

Hi Jose

How to convert the string column to other data types like "real" while creating calculated column using python?

Thanks

Jose Leviaguirre said...

Do the cast in the expression itself. For example:

newColExpr = "real(Trim([myTableCol]))"

Walktheway said...

That worked like a charm. thanks

Oliver Drummond said...

That's great! Is it also possible to Update de calculated columns using something similar?