Get Average Of Multiple Selected Rows In Table

Hi All

I have a table which records Yield and a request has come in for the option to select multiple rows( similar to excel) and get the the instant yield for those selected rows. I am wondering how I can accomplish this. I have turned on multiple interval but when I select multiple rows nothing gets generated in the properties of the table. I can extract 1 row value quite easily but am at a loss as how to go about getting the yield for the selected rows.

Thanks

Aidan

In this case you have to write a script to get all of the selected rows. You can do something like on the mouseReleased event of the table:table = event.source data = table.data rows = table.getSelectedRows() avg = 0.0 if len(rows) > 0: sum = 0.0 for row in rows: value = data.getValueAt(row, "Col 3") sum = sum + value avg = sum / len(rows) event.source.parent.getComponent('Label').text = str(avg)You can change up the logic and change which column to perform the calculation on. In my case I am using column “Col 3”, just switch that to your column name. This code loops through all of the selected rows of the table and performs the calculation. At the end it sets a label’s text with the calculation.

1 Like

Hi Travis

Thanks for that, it worked perfectly

Aidan