4

I'm using Spotfire and would like to know if there's a way of updating or removing a calculated column using IronPython code.

Ex: Let's pretend I have a table with: | Column 1 | Column 2| Column 3 | Calculated Column |

So, every time I run a specific script, I want it to change the values of the calculated Column.

PS: I already have the below code to create the column if needed. So, if there is at least a way of deleting the column, it would also work for me.

from Spotfire.Dxp.Data import CalculatedColumn

newColName = "MY_CALCULATED_COLUMN"
newColExpr = "TRIM([myTableCol])"
Document.Data.Tables["MY_TABLE"].Columns.AddCalculatedColumn(newColName,newColExpr).As[CalculatedColumn]()
Oliver Drummond
  • 680
  • 1
  • 6
  • 19
  • 2
    I haven't tested it yet, but I'm curious why the solution over at https://stackoverflow.com/questions/21108946/remove-delete-or-hide-column-in-spotfire didn't work for you? – niko Mar 26 '18 at 12:54
  • 2
    I've tested this one. Unfortunately, it's only removing the column from the table visualisation, not from the data table itself. – Oliver Drummond Mar 27 '18 at 00:57
  • gotcha, looking at it a second time I see what you mean :) lemme poke around a bit. – niko Mar 27 '18 at 13:20

1 Answers1

4

the following code will work for you:

newColName = "col"
Document.Data.Tables["Data Table"].Columns.Remove(newColName)

(you don't need to import any classes for this one)

you can find additional info in the API documentation.

niko
  • 3,946
  • 12
  • 26