Jump to content

How to give document property value into Table.Select()


Recommended Posts

This question is based onhttps://community.spotfire.com/questions/fetching-specific-cell-datatable-u...

For example: in the table below i want to find sales corresponding to period 2017-2 (i.e. 300)

 

 

 

 

Period

Sales

 

 

2017-1

400

 

 

2017-2

300

 

 

2017-3

500

 

 

 

I am able to get it using the answer:

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('Period = "2017-2"')

 

# Create a cursor to the Column we wish to get the values from

cursor = DataValueCursor.CreateFormatted(table.Columns["Sales"])

 

# Create List object that will hold values

listofValues=List[str]()

 

# 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(value1)

 

 

for val in listofValues:

print valbut in line 6, can anyone tell me how to specify an value of document property instead of "2017-2"

Link to comment
Share on other sites

The simplest way would be to substitute

rowSelection=table.Select('Period = "2017-2"')

with

chosenPeriod = Document.Properties[nameOfYourDocumentProperty]

rowSelection=table.Select('Period= ' + str(chosenPeriod)+ '"')

where the final '"' is meant to be ' followed by " followed by '

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...