# Math functions in power table

**URL:** <https://forum.inductiveautomation.com/t/math-functions-in-power-table/58814>\
**Category:** Ignition\
**Created:** [April 25, 2022, 2:43pm UTC](https://forum.inductiveautomation.com/t/math-functions-in-power-table/58814 "2022-04-25T14:43:20Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [April 25, 2022, 2:43pm UTC](https://forum.inductiveautomation.com/t/math-functions-in-power-table/58814/1 "2022-04-25T14:43:20Z")

</div>

how do I divide two columns and put the answer in another column in an power table? This is what I have tried.

```auto
if colName == "% of FLA":
		data.getValueAt(rowIndex,"Amps" )/data.getValueAt (rowIndex,"FLA")
		returnValue	

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [April 25, 2022, 2:52pm UTC](https://forum.inductiveautomation.com/t/math-functions-in-power-table/58814/2 "2022-04-25T14:52:36Z")

</div>

This kind of looks like you have this script in the `configureCell` extension funciton, which isn’t where you want to do this calculation. Where is the data for this table coming from? If it is a db query, is it triggered manually, or do you have a polling rate?

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [April 25, 2022, 2:54pm UTC](https://forum.inductiveautomation.com/t/math-functions-in-power-table/58814/3 "2022-04-25T14:54:30Z")

</div>

all the data is manually entered except the amps column which is done with cell update binding

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [April 25, 2022, 3:04pm UTC](https://forum.inductiveautomation.com/t/math-functions-in-power-table/58814/4 "2022-04-25T15:04:42Z")

</div>

If you are manually entering the `FLA` portion, then you could use a `onCellEdited` extension function.

```auto
if newValue:
	data = self.data
	flaPercentage = data.getValueAt(rowIndex,"Amps" ) / newValue
	newData = system.dataset.setValue(data, rowIndex, '% of FLA', flaPercentage)
	self.data = newData

```

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [April 25, 2022, 3:32pm UTC](https://forum.inductiveautomation.com/t/math-functions-in-power-table/58814/5 "2022-04-25T15:32:32Z")

</div>

sorry, it only gets entered in when I set the table up manually. It will always stay the same.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [April 25, 2022, 3:33pm UTC](https://forum.inductiveautomation.com/t/math-functions-in-power-table/58814/6 "2022-04-25T15:33:35Z")

</div>

Yeah I wasn’t thinking right, you want the % col to update as the Amps col updates…

```auto
if event.propertyName == 'data':
	data = event.source.data
	pyData= system.dataset.toPyDataSet(data)
	header = ['Amps','FLA','% of FLA']
	newData = []
	for row in pyData:
		amps = row['Amps']
		fla = row['FLA']
		newRow = [amps,fla, amps / fla]
		newData.append(newRow)
	event.source.data = system.dataset.toDataSet(header,newData)

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 25, 2022, 4:54pm UTC](https://forum.inductiveautomation.com/t/math-functions-in-power-table/58814/7 "2022-04-25T16:54:44Z")

</div>

‘A’ or ‘ampere’ or ‘amps’. SI units named after a person are lowercase when spelt out!  
The symbols have their first letter capitalised (‘A’, ‘V’, ‘Hz’, ‘Pa’ etc.)

---

<div class="post-metadata">

**Author:** ![andrew.thull](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@andrew.thull](https://forum.inductiveautomation.com/u/andrew.thull)\
**Post date:** [September 7, 2022, 7:24pm UTC](https://forum.inductiveautomation.com/t/math-functions-in-power-table/58814/8 "2022-09-07T19:24:46Z")

</div>

What is the pyData in this example?

I have a Power Table where I’d like to divide the actual column by the target column.

The Power Table obtains data through an SQL Query. Ignition support pointed me to this thread, but it’s not clear how I enter the configureCell script to divide the actual by the target in a new column. Thank you.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [September 7, 2022, 7:33pm UTC](https://forum.inductiveautomation.com/t/math-functions-in-power-table/58814/9 "2022-09-07T19:33:38Z")

</div>

Why not do the division in your query instead of a script?

pseudo SQL

```auto
select actual, target, round(actual/target,3) as percentage
from <your_table>
where ...

```

---

<div class="post-metadata">

**Author:** ![jshaffer09](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@jshaffer09](https://forum.inductiveautomation.com/u/jshaffer09)\
**Post date:** [September 7, 2022, 7:49pm UTC](https://forum.inductiveautomation.com/t/math-functions-in-power-table/58814/10 "2022-09-07T19:49:23Z")

</div>

This is how I am doing it, the data I am using is just typed in except the amps column which I use a cell update binding

```auto
         #Imports
	from java.awt import Font
	
        #Table data
	data = self.data		
	returnValue = {}	

	#% of FLA
	if (colName == '% of FLA'):
		col1 = self.data.getValueAt(rowIndex, "FLA")
		col2 = self.data.getValueAt(rowIndex, "Amps")
		if col2:
			col3 = int(100*(col2/col1))
			return {'text': col3}

```

---

<div class="post-metadata">

**Author:** ![andrew.thull](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@andrew.thull](https://forum.inductiveautomation.com/u/andrew.thull)\
**Post date:** [September 8, 2022, 6:22pm UTC](https://forum.inductiveautomation.com/t/math-functions-in-power-table/58814/11 "2022-09-08T18:22:28Z")

</div>

Thank you. I found another way to get the data I needed so I didn’t have to do math after all.

---

<div class="post-metadata">

**Author:** ![andrew.thull](https://avatars.discourse-cdn.com/v4/letter/a/7ea924/32.png) [@andrew.thull](https://forum.inductiveautomation.com/u/andrew.thull)\
**Post date:** [September 8, 2022, 6:32pm UTC](https://forum.inductiveautomation.com/t/math-functions-in-power-table/58814/12 "2022-09-08T18:32:01Z")

</div>

Thank you, that’s so much easier than what I was trying!
