# Power Table Configuration Cell Script Help(Solved)

**URL:** <https://forum.inductiveautomation.com/t/power-table-configuration-cell-script-help-solved/16608>\
**Category:** Ignition\
**Created:** [January 16, 2018, 3:06pm UTC](https://forum.inductiveautomation.com/t/power-table-configuration-cell-script-help-solved/16608 "2018-01-16T15:06:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![TruThat](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@TruThat](https://forum.inductiveautomation.com/u/TruThat)\
**Post date:** [January 16, 2018, 3:06pm UTC](https://forum.inductiveautomation.com/t/power-table-configuration-cell-script-help-solved/16608/1 "2018-01-16T15:06:06Z")

</div>

Using a Power Table. I am trying to compare the value to the row below. If the values are different I want the text to be ‘red’ and if the values are the same ‘white’. This is my code that I am using. It works up to the point where the rows end(last row). How do find and escape out of the routine if it is the last row in the table; this would stop errors with ArrayIndexOutOfBoundsException.

This is the code in the def configureCell function:

```auto
	if selected:
			return {'foreground' : 'red','background': self.selectionBackground}	
	elif rowView % 2 == 0:
		if value != self.data.getValueAt(rowIndex + 1,colIndex):
			return {'background': 'black','foreground' : 'red'}	
		else:
			return {'background': 'black','foreground' : 'white'}
	else:
		if value != self.data.getValueAt(rowIndex + 1,colIndex):
			return {'background': 'blue','foreground' : 'red'}
		else:
			return {'background': 'blue','foreground' : 'white'}

```

---

<div class="post-metadata">

**Author:** ![c.bertulli](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@c.bertulli](https://forum.inductiveautomation.com/u/c.bertulli)\
**Post date:** [January 16, 2018, 4:07pm UTC](https://forum.inductiveautomation.com/t/power-table-configuration-cell-script-help-solved/16608/2 "2018-01-16T16:07:46Z")

</div>

Can you please explain better the issue?  
You mentioned “It works up to the point where the rows end”, are you using a **while loop** or a **for loop**?  
If you just want to know how many rows your table have, use the command **len()**

`print len(table)` will print out the table’s lenght

---

<div class="post-metadata">

**Author:** ![TruThat](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@TruThat](https://forum.inductiveautomation.com/u/TruThat)\
**Post date:** [January 16, 2018, 4:16pm UTC](https://forum.inductiveautomation.com/t/power-table-configuration-cell-script-help-solved/16608/3 "2018-01-16T16:16:50Z")

</div>

i didn’t not think you could use len(table) in a Power Table. Could I use self.table?

---

<div class="post-metadata">

**Author:** ![c.bertulli](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@c.bertulli](https://forum.inductiveautomation.com/u/c.bertulli)\
**Post date:** [January 16, 2018, 4:40pm UTC](https://forum.inductiveautomation.com/t/power-table-configuration-cell-script-help-solved/16608/4 "2018-01-16T16:40:19Z")

</div>

I just tried to populate a Power Table with a DataSet took from a query and then use the len() function.

```auto
query = "SELECT Data_Var_1,Data_Var_2,Data_Var_3 FROM Table"
QueryTable = system.db.runQuery(query,'DBname')
event.source.data = QueryTable
last_row = len(QueryTable) 

```

---

<div class="post-metadata">

**Author:** ![TruThat](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@TruThat](https://forum.inductiveautomation.com/u/TruThat)\
**Post date:** [January 16, 2018, 4:54pm UTC](https://forum.inductiveautomation.com/t/power-table-configuration-cell-script-help-solved/16608/5 "2018-01-16T16:54:36Z")

</div>

I don’t think you can put this in the configureCell Extension functions script area…I will add that to my issue above

---

<div class="post-metadata">

**Author:** ![TruThat](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@TruThat](https://forum.inductiveautomation.com/u/TruThat)\
**Post date:** [January 16, 2018, 5:40pm UTC](https://forum.inductiveautomation.com/t/power-table-configuration-cell-script-help-solved/16608/6 "2018-01-16T17:40:16Z")

</div>

this works now…

```auto
	if rowIndex < self.data.rowCount -1:
		if selected:
			return {'foreground' : 'red','background': self.selectionBackground}	
		elif rowView % 2 == 0:
			if value != self.data.getValueAt(rowIndex + 1,colIndex):
				return {'background': 'black','foreground' : 'red'}	
			else:
				return {'background': 'black','foreground' : 'white'}
		else:
			if value != self.data.getValueAt(rowIndex + 1,colIndex):
				return {'background': 'blue','foreground' : 'red'}
			else:
				return {'background': 'blue','foreground' : 'white'}

```
