# How to get first and last value of evey column -power table -

**URL:** <https://forum.inductiveautomation.com/t/how-to-get-first-and-last-value-of-evey-column-power-table/75913>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [July 4, 2023, 10:37pm UTC](https://forum.inductiveautomation.com/t/how-to-get-first-and-last-value-of-evey-column-power-table/75913 "2023-07-04T22:37:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rigoberto.reyes](https://avatars.discourse-cdn.com/v4/letter/r/65b543/32.png) [@rigoberto.reyes](https://forum.inductiveautomation.com/u/rigoberto.reyes)\
**Post date:** [July 4, 2023, 10:37pm UTC](https://forum.inductiveautomation.com/t/how-to-get-first-and-last-value-of-evey-column-power-table/75913/1 "2023-07-04T22:37:12Z")

</div>

Hi there.

How can I get the first and last values of every column from a power table?, selected values must be \<\> 0 like next image

 ![imagen](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/8/787edd2a2e7af4eab0ae7088de160ff53deeaa97.png)

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [July 5, 2023, 5:05am UTC](https://forum.inductiveautomation.com/t/how-to-get-first-and-last-value-of-evey-column-power-table/75913/2 "2023-07-05T05:05:09Z")

</div>

From your picture, it doesn't look like you are simply wanting the first and last non-zero values; it looks like you are wanting the first and last non-zero values that are currently displayed in the scrollpane? Is this correct?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [July 5, 2023, 8:36am UTC](https://forum.inductiveautomation.com/t/how-to-get-first-and-last-value-of-evey-column-power-table/75913/3 "2023-07-05T08:36:58Z")

</div>

If you are simply trying to get the first and last non zero value from the dataset as independent lists, this script will do that for you:

```auto
powerTable = event.source.parent.getComponent('Power Table')#Replace with relative powerTable path
data = powerTable.data
topRow = []
lastRow = []
for column in range(data.columnCount):
	columnData = data.getColumnAsList(column)
	zerolessData = [value for value in columnData if value != 0]
	topRow.append(zerolessData[0] if zerolessData else None)
	lastRow.append(zerolessData[-1] if zerolessData else None)
print topRow
print lastRow

```

It gets each column as a list, removes the zero values, and then makes lists with the first and last values that remain in each column.

However, if you only want the first and last non zero values of the visible portion of the table, as your picture indicates, then you will need to get the visible indexes using viewport's view rectangle's location and size. Here is a script that does this:

```auto
from java.awt import Point
powerTable = event.source.parent.getComponent('Power Table')#Replace with relative powerTable path
table = powerTable.table
data = powerTable.data
viewport = table.parent
viewRect = viewport.viewRect
startIndex = table.rowAtPoint(viewRect.location)
endIndex = table.rowAtPoint(Point(viewRect.location.x, (viewRect.location.y + viewRect.size.height)))
topRow = []
lastRow = []
for column in range(data.columnCount):
	columnData = [data.getValueAt(row, column) for row in range(startIndex, endIndex)]
	zerolessData = [value for value in columnData if value != 0]
	topRow.append(zerolessData[0] if zerolessData else None)
	lastRow.append(zerolessData[-1] if zerolessData else None)
print topRow
print lastRow

```
