Search code examples
ironpythontibcospotfire

How to add calculated columns and perform Calculations with IronPython Script in Spotfire


I am using this script (below) to create a calculate column [NEWCOLUMN] in Spotfire using IronPython:

from Spotfire.Dxp.Data import CalculatedColumn

cols = Document.Data.Tables["TIBER"].Columns

cols.AddCalculatedColumn("NEWCOLUMN");

How do I control the datatype of the calculated column? Also, then what is the processes to edit the expression of the calculated column? For example, I would like NEWCOLUMN = [oldcolumn]*3.289

Thanks!


Solution

  • Your calculated column will inherit the data type from the expression in <arg2> of AddCalculatedColumn(<arg1>,<arg2>).

    i.e.

    from Spotfire.Dxp.Data import CalculatedColumn
    cols = Document.Data.Tables["TIBER"].Columns
    cols.AddCalculatedColumn("NEWCOLUMN","[oldcolumn] * 3.289");
    

    Roll Tide.