Andrew Malby Posted June 29, 2022 Share Posted June 29, 2022 I need to extract the max value from a filtered datatable, and pass to a Document Property. I can find the last date from the filter like this: dt.Columns["COLUMN"].RowValues.GetValue(rows.Last) But if do that for a numeric 'real' column it extracts the last value from the data table, not from the filter. I then tried: dt.Columns["COLUMN"].RowValues.GetMaxValue(rows), but the output is in the format 'DataValue[value=10.372]'... and I can't see how to change the format or extract the numbers. Any help gratefully received! Link to comment Share on other sites More sharing options...
Gaia Paolini Posted June 30, 2022 Share Posted June 30, 2022 Taking inspiration from this https://community.spotfire.com/wiki/ironpython-script-iterate-over-filtered... adding a missing import, removing an extra parenthesis and adding a values list to calculate the maximum of, this should help. Example done on the 'iris' data table. Make sure 'Filtering scheme' is the exact name of your filtering scheme, and I am assuming the column values are all floats (you probably want to put additional checks). The document property needs to exist before you run the script. # Copyright 2022. TIBCO Software Inc. Licensed under TIBCO BSD-style license. from Spotfire.Dxp.Data import * # Specify the data table used in Spotfire dataTable = Document.Data.Tables["iris"] # Get a reference to the specified filtering scheme on the data table above dataFilteringSelection = Document.Data.Filterings["Filtering scheme"] filteringScheme = Document.FilteringSchemes[dataFilteringSelection] filterCollection = filteringScheme[dataTable] # Filtered rows based on the scheme above filteredRows = filterCollection.FilteredRows # Specify the column in the data table to get the values myColCursor = DataValueCursor.CreateFormatted(dataTable.Columns["Sepal_Width"]) values=[] # Iterate over the filtered rows for row in dataTable.GetRows(filteredRows,myColCursor): # cursorValue will now contain the value for the column at the current row position cursorValue = myColCursor.CurrentValue values.append(float(cursorValue)) max_value=max(values) print(max_value) Document.Properties['maxValue']=max_value 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