# Get difference of two cells and place that value into another cell

**URL:** <https://forum.inductiveautomation.com/t/get-difference-of-two-cells-and-place-that-value-into-another-cell/63007>\
**Category:** Ignition\
**Tags:** ignition81, vision\
**Created:** [August 15, 2022, 6:58pm UTC](https://forum.inductiveautomation.com/t/get-difference-of-two-cells-and-place-that-value-into-another-cell/63007 "2022-08-15T18:58:11Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raymond\_Sipes](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@Raymond\_Sipes](https://forum.inductiveautomation.com/u/Raymond_Sipes)\
**Post date:** [August 15, 2022, 6:58pm UTC](https://forum.inductiveautomation.com/t/get-difference-of-two-cells-and-place-that-value-into-another-cell/63007/1 "2022-08-15T18:58:11Z")

</div>

Hello!

I am trying to get the difference of the status and goal column and place it in the Behind/ Ahead column. I have looked into the `system.dataset` functions, but I do not see any mathematical equations within the manual. This is the screenshot below, I am using a regular table form the component palette in vision.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/d/0d2eba026f2307bb8bc637eefe22b8f81b458dc6.png)

Let me know if if you need anymore information!

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 15, 2022, 7:04pm UTC](https://forum.inductiveautomation.com/t/get-difference-of-two-cells-and-place-that-value-into-another-cell/63007/2 "2022-08-15T19:04:29Z")

</div>

How are you getting the data into the table currently?

You could bind this data to a custom property, then rebuild the dataset, using the calulated value.

My answer will likely change depending on the answer. 😉

---

<div class="post-metadata">

**Author:** ![Raymond\_Sipes](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@Raymond\_Sipes](https://forum.inductiveautomation.com/u/Raymond_Sipes)\
**Post date:** [August 15, 2022, 7:07pm UTC](https://forum.inductiveautomation.com/t/get-difference-of-two-cells-and-place-that-value-into-another-cell/63007/3 "2022-08-15T19:07:16Z")

</div>

Currently it is just through the dataset. I made the table editable and they would input the values within the weekly needs, status and goal. The remaining and Behind/ ahead would be calculated for them. Each row in my table will have differing data, not sure if that would mess up the custom property idea!

Thank you

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 15, 2022, 7:34pm UTC](https://forum.inductiveautomation.com/t/get-difference-of-two-cells-and-place-that-value-into-another-cell/63007/4 "2022-08-15T19:34:42Z")

</div>

> [@Raymond\_Sipes](#):
>
> Each row in my table will have differing data, not sure if that would mess up the custom property idea!

Not at all, though make sure you make the calculated columns un-editable. Though there really isn't a need for a custom property if your data is only ever going to reside in the table, and you don't need to keep a copy of the unmodified dataset.

Also, user data entry should be validated, so I would probably use the cellEdited event on the table to validate the data entry and then an external component to have the user trigger an update to the table when all the data has been entered.

So for instance you might place this script in a Button's `actionPerformed` script.

```auto
#get data from table
data = event.source.parent.getComponent('YourTableName').data

#convert data to a pyDataSet (technically not requiered but makes working with the data much easier
pyData = system.dataset.toPyDataSet(data)

#loop through each row and do calculations
for row in pyData:
    row['Behind / Ahead'] = row['Goal'] - row['Status']

#update the table with the new dataset
event.source.parent.getComponent('YourTableName').data = system.dataset.toDataSet(pyData)

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 15, 2022, 7:39pm UTC](https://forum.inductiveautomation.com/t/get-difference-of-two-cells-and-place-that-value-into-another-cell/63007/5 "2022-08-15T19:39:17Z")

</div>

If you are looking to keep it inside the table, then consider using a power table instead. It will give you more options. Here’s a window you can play with.

[TableUpdate.zip](https://forum.inductiveautomation.com/uploads/short-url/gyNQ2lpFXDfdfFfrJpHdLhB8NGr.zip) (8.1 KB)

The internal function onCellEdited() can take care if it for you.

```python
def onCellEdited(self, rowIndex, colIndex, colName, oldValue, newValue):
	data = self.data
	data = system.dataset.setValue(data, rowIndex, colIndex, newValue)
	difference = data.getValueAt(rowIndex, 'Status') - data.getValueAt(rowIndex, 'Goal')
	data = system.dataset.setValue(data, rowIndex, 'Behind / Ahead', difference)
	self.data = data

```

---

<div class="post-metadata">

**Author:** ![Raymond\_Sipes](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@Raymond\_Sipes](https://forum.inductiveautomation.com/u/Raymond_Sipes)\
**Post date:** [August 15, 2022, 7:44pm UTC](https://forum.inductiveautomation.com/t/get-difference-of-two-cells-and-place-that-value-into-another-cell/63007/6 "2022-08-15T19:44:56Z")

</div>

Thank you so much! That seemed as though it would work but it does say

> Traceback (most recent call last):  
> File "event:actionPerformed", line 9, in   
> TypeError: com.inductiveautomation.ignition.common.script.builtin.DatasetUtilities$PyDataSet$PyRow indices must be integers

I went ahead and tried @JordanCClark solution which worked!

Thank you again for your help!

---

<div class="post-metadata">

**Author:** ![Raymond\_Sipes](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@Raymond\_Sipes](https://forum.inductiveautomation.com/u/Raymond_Sipes)\
**Post date:** [August 15, 2022, 7:45pm UTC](https://forum.inductiveautomation.com/t/get-difference-of-two-cells-and-place-that-value-into-another-cell/63007/7 "2022-08-15T19:45:54Z")

</div>

Thank you sir! This worked as intended, I did not think to use a power table for this functionality!

Have a great day!

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 15, 2022, 7:47pm UTC](https://forum.inductiveautomation.com/t/get-difference-of-two-cells-and-place-that-value-into-another-cell/63007/8 "2022-08-15T19:47:09Z")

</div>

You can also use the configureCell() function to color the cells / text, if needed

---

<div class="post-metadata">

**Author:** ![Raymond\_Sipes](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@Raymond\_Sipes](https://forum.inductiveautomation.com/u/Raymond_Sipes)\
**Post date:** [August 15, 2022, 7:48pm UTC](https://forum.inductiveautomation.com/t/get-difference-of-two-cells-and-place-that-value-into-another-cell/63007/9 "2022-08-15T19:48:31Z")

</div>

I was going to ask about coloring the first header cell, but thought it would be too bothersome lol. Would configureCell() work for that as well?

Thank you

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 15, 2022, 8:04pm UTC](https://forum.inductiveautomation.com/t/get-difference-of-two-cells-and-place-that-value-into-another-cell/63007/10 "2022-08-15T20:04:12Z")

</div>

configureHeaderStyle() is for that.

```python
def configureHeaderStyle(self, colIndex, colName):
	# Example:
	from javax.swing import SwingConstants
	from java.awt import Color
	config = {'foreground': 'black',
	          'background' : 'lightGray',
			  'horizontalAlignment': SwingConstants.CENTER}
	
	if colName == 'Core':
		config['background'] = Color(217, 217, 0)
		# config['background'] = 'yellow'
	
	return config

```

---

<div class="post-metadata">

**Author:** ![Raymond\_Sipes](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@Raymond\_Sipes](https://forum.inductiveautomation.com/u/Raymond_Sipes)\
**Post date:** [August 15, 2022, 8:05pm UTC](https://forum.inductiveautomation.com/t/get-difference-of-two-cells-and-place-that-value-into-another-cell/63007/11 "2022-08-15T20:05:01Z")

</div>

Perfect, thank you again for the valuable information!
