# Get Average Of Multiple Selected Rows In Table

**URL:** <https://forum.inductiveautomation.com/t/get-average-of-multiple-selected-rows-in-table/2677>\
**Category:** Ignition\
**Created:** [February 23, 2011, 4:01pm UTC](https://forum.inductiveautomation.com/t/get-average-of-multiple-selected-rows-in-table/2677 "2011-02-23T16:01:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aidamcg](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@aidamcg](https://forum.inductiveautomation.com/u/aidamcg)\
**Post date:** [February 23, 2011, 4:01pm UTC](https://forum.inductiveautomation.com/t/get-average-of-multiple-selected-rows-in-table/2677/1 "2011-02-23T16:01:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [February 23, 2011, 4:56pm UTC](https://forum.inductiveautomation.com/t/get-average-of-multiple-selected-rows-in-table/2677/2 "2011-02-23T16:56:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![aidamcg](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@aidamcg](https://forum.inductiveautomation.com/u/aidamcg)\
**Post date:** [February 24, 2011, 7:24am UTC](https://forum.inductiveautomation.com/t/get-average-of-multiple-selected-rows-in-table/2677/3 "2011-02-24T07:24:52Z")

</div>

Hi Travis

Thanks for that, it worked perfectly

Aidan
