Sundaram Sridharan Posted November 26, 2020 Share Posted November 26, 2020 I need to check if a column is present (which came in through a pivot operation) and if not I need to add it to the table with blank values for all rows. I am looking for syntax of table.AddColumns for this (what is datasource here). Also can this be only triggered by an action item in text area Ideally I would like to add this as a transform right after pivot in data canvas. Link to comment Share on other sites More sharing options...
Gaia Paolini Posted November 26, 2020 Share Posted November 26, 2020 Try this (replace column names and data types as required): check the indentation (got mixed up when pasting) from Spotfire.Dxp.Data import * desiredColsDict = {'mydatecol':DataType.Date,'myintegercol':DataType.Integer,'mystringcol':DataType.String} for key,value in desiredColsDict.items(): try: expression = str(value)+'(NULL)' dataTable.Columns.AddCalculatedColumn(key,expression) except: pass Link to comment Share on other sites More sharing options...
Gaia Paolini Posted November 29, 2020 Share Posted November 29, 2020 forgot to add that dataTable will be the input parameter (of type data table). Instead of using the e.g. DataType.String you could put the actual value (in this case, 'String'). Seems that adding a null column needs a cast to the appropriate data type, otherwise it defaults to Integer. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now