# Summing column values in selected rows

**URL:** <https://forum.inductiveautomation.com/t/summing-column-values-in-selected-rows/28367>\
**Category:** Ignition\
**Created:** [September 18, 2019, 10:28pm UTC](https://forum.inductiveautomation.com/t/summing-column-values-in-selected-rows/28367 "2019-09-18T22:28:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RRagan](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@RRagan](https://forum.inductiveautomation.com/u/RRagan)\
**Post date:** [September 18, 2019, 10:28pm UTC](https://forum.inductiveautomation.com/t/summing-column-values-in-selected-rows/28367/1 "2019-09-18T22:28:59Z")

</div>

I have a power table that updates from a database. I am able to Sum the total column value by binding the value of my numeric label to SUM({Root Container.GS Table.data},4).

How can I get a value for the sum of the current selection in that column?

I.E. I want to allow the operator to select, say, 10 rows out of the table, and a numeric label to correctly populate the sum of the values in Column 4 of only those selected 10 rows.

---

<div class="post-metadata">

**Author:** ![osolorzano](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/osolorzano/32/6432_2.png) [@osolorzano](https://forum.inductiveautomation.com/u/osolorzano)\
**Post date:** [September 18, 2019, 11:44pm UTC](https://forum.inductiveautomation.com/t/summing-column-values-in-selected-rows/28367/2 "2019-09-18T23:44:37Z")

</div>

On the Power Table, if you go to it’s scripting methods and enable its onMouseClick() extension function you can do a simple script like:

```auto
	columnToSum = 1 # This is the column you want to start summing
	sum = 0
	for row in self.selectedRows:	# self.selectedRows is an array of the currently selected rows
		sum += self.data.getValueAt(row,columnToSum)
	self.parent.getComponent('Numeric Label').value = sum # Set this sum to the value of the numeric label

```

---

<div class="post-metadata">

**Author:** ![RRagan](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@RRagan](https://forum.inductiveautomation.com/u/RRagan)\
**Post date:** [September 26, 2019, 11:16pm UTC](https://forum.inductiveautomation.com/t/summing-column-values-in-selected-rows/28367/3 "2019-09-26T23:16:25Z")

</div>

I think this has an indentation error. When I fix that, I get a value of 0 regardless of the values in that column.

---

<div class="post-metadata">

**Author:** ![RRagan](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@RRagan](https://forum.inductiveautomation.com/u/RRagan)\
**Post date:** [September 26, 2019, 11:35pm UTC](https://forum.inductiveautomation.com/t/summing-column-values-in-selected-rows/28367/4 "2019-09-26T23:35:53Z")

</div>

Ok. I was putting this code in the MouseClicked Event Handler rather than the onMousePress extension function. That was my problem.  
Now, in order for the numeric label to update properly, I need to highlight the rows I was to sum, and then let go and click on the table again.

This should suffice.  
Thank You.

---

<div class="post-metadata">

**Author:** ![osolorzano](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/osolorzano/32/6432_2.png) [@osolorzano](https://forum.inductiveautomation.com/u/osolorzano)\
**Post date:** [September 27, 2019, 3:35pm UTC](https://forum.inductiveautomation.com/t/summing-column-values-in-selected-rows/28367/5 "2019-09-27T15:35:16Z")

</div>

If you use the onMouseClick() extension function instead of the onMousePress() extension function you shouldn’t have to click the table again after selecting some rows.
