Jump to content

Get Max / Min of Filtered Rows in Column


Sean Conroy

Recommended Posts

I know how to get the filtered rows of a column in IronPython:

 

myTable = Document.Data.Tables["Table"]

dataFilteringSelection = Document.Data.Filterings["Filter"]

filteringScheme = Document.FilteringSchemes[dataFilteringSelection]

filterCollection = filteringScheme[myTable]

filteredRows = filterCollection.FilteredRows

 

myCursor = DataValueCursor.CreateFormatted(myTable.Columns["myColumn"])

# Iterate over the filtered rows

for row in Reference.GetRows(filteredRows,myCursor):

val = float(myCursor.CurrentValue)

if val > maxVal:

maxVal = val

 

And I know how to get the min and max of a column using IronPython:

min = myTable.Columns['myColumn'].RowValues.GetMinValue().Value

max = myTable.Columns['myColumn'].RowValues.GetMaxValue().ValueBut is there a way to get thefilteredmin and max values from the column, without having to iterate through the column, comparing each value against the current min / max This is very slow for large tables, and I'm trying to adjust visualization properties, but this will bother the user.

Link to comment
Share on other sites

Use a python script to get the min and max values from thefilter :

 

 

#get list of filtered rows

dt = Document.ActiveDataTableReference

#This line implements the current filtering

rows = Document.ActiveFilteringSelectionReference.GetSelection(dt).AsIndexSet()

 

#get min and max values from the set

min = dt.Columns["column1"].RowValues.GetFormattedValue(rows.First)

max = dt.Columns["column1"].RowValues.GetFormattedValue(rows.Last)

 

print(min)

print(max)

https://spotfired.blogspot.com/2014/07/get-min-and-max-values-from-range-filter.html

Link to comment
Share on other sites

myTable = Document.Data.Tables["myTable"]

 

rows = Document.Data.Filterings["My Filter"].GetSelection(myTable).AsIndexSet()

 

min = myTable.Columns['myColumn'].RowValues.GetMinNumericValue(rows)

max = myTable.Columns['myColumn'].RowValues.GetMaxNumericValue(rows)This is what worked for me, based on the answer above with a few adjustments.

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...