Jump to content
  • How to limit a Data table , perform an Aggregation and save the value to a document property in Spotfire® Using IronPython Scripting


    Sample script to initially limit the data table, perform some aggregation/calculation and then save the value to a document property. Using this we can simulate capturing the Calculated Value from the Text Area.

    Introduction

    Below is a sample script where we initially limit the data table, perform some aggregation/calculation and then save the value to a document property. Using this we can simulate capturing the Calculated Value from the Text Area.

    Code Sample

    # Copyright © 2017. TIBCO Software Inc. Licensed under TIBCO BSD-style license.
    
    from Spotfire.Dxp.Data import *
    from System.Collections.Generic import List
    
    table=Document.ActiveDataTableReference
    # select an expression to limit the data in a table 
    rowSelection=table.Select('AT_BATS <= 185')
    
    # Create a cursor to the Column we wish to get the values from
    cursor = DataValueCursor.CreateFormatted(table.Columns["AT_BATS"])
    
    # Create List object that will hold values
    listofValues=List[int]()
    
    # Loop through all rows, retrieve value for specific column,
    # and add value into list
    for  row in  table.GetRows(rowSelection.AsIndexSet(),cursor):
       rowIndex = row.Index
       value1 = cursor.CurrentValue
       listofValues.Add(int(value1))
    
    #values=list(set(strArray))
    print sum(listofValues)
    Document.Properties["Sum"]=sum(listofValues)
     

    References

    License: TIBCO BSD-Style License

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...