# How to return a row and column of specific data from a dataset

**URL:** <https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101>\
**Category:** Ignition\
**Created:** [June 23, 2021, 12:18pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101 "2021-06-23T12:18:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![felipe2010silva](https://avatars.discourse-cdn.com/v4/letter/f/54ee81/32.png) [@felipe2010silva](https://forum.inductiveautomation.com/u/felipe2010silva)\
**Post date:** [June 23, 2021, 12:18pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/1 "2021-06-23T12:18:03Z")

</div>

Good Morning.

My name is Felipe. I have spent time finding a solution for an application, but without success. The idea is that every time the dataset has the word “Label Exchance” or even the code “500”, the system returns the row and column they are in, it can be a label, for example. See attached image

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/c/2caf09a36fa98bb9eadf62f75ac6a5550debaba3.png)

Thank You

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 23, 2021, 12:40pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/2 "2021-06-23T12:40:28Z")

</div>

I would use the [view()](https://www.automation-pros.com/simaids/doc/expression.view.html) expression function from my [Simulation Aids](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-simulation-aids) module.

Add a custom dataset property to your table with this expression:

```auto
view("Select _r As rowIndex Where Reason_Code==500", {Root Container.path.to.table.data})

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 23, 2021, 12:41pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/3 "2021-06-23T12:41:03Z")

</div>

Or you can use a propertyChange script to search the dataset.

---

<div class="post-metadata">

**Author:** ![felipe2010silva](https://avatars.discourse-cdn.com/v4/letter/f/54ee81/32.png) [@felipe2010silva](https://forum.inductiveautomation.com/u/felipe2010silva)\
**Post date:** [June 23, 2021, 12:59pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/5 "2021-06-23T12:59:11Z")

</div>

@pturmel was not authorized to install the module. How do I do using a PropertyChange script?

---

<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:** [June 23, 2021, 1:07pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/6 "2021-06-23T13:07:54Z")

</div>

```auto
# Creaste sample dataset
sampleHeaders = ['letter', 'number']
sampleData = [['A', 1],
              ['B', 2],
              ['A', 3],
              ['B', 4],
              ['C', 5],
              ['A', 6],
              ['B', 7],
              ['C', 8],
              ['D', 9],
              ['A', 10],
              ['B', 11],
              ['C', 12],
              ['D', 13],
              ['E', 14]
             ]       
dataSet = system.dataset.toDataSet(sampleHeaders, sampleData)

# -----------------------------------------------------------#

def findEquals(datasetIn, colName, value):
	# Convert to PyDataSet
	dataIn = system.dataset.toPyDataSet(datasetIn)

	headers = list(dataIn.getColumnNames())
	dataOut = [row for row in dataIn if row[colName] == value]

	return system.dataset.toDataSet(headers, dataOut)

findData = findEquals(dataSet, 'letter', 'B')

```

result:

```nohighlight
row | letter | number
---------------------
0 | B | 2     
1 | B | 4     
2 | B | 7     
3 | B | 11 

```

---

<div class="post-metadata">

**Author:** ![felipe2010silva](https://avatars.discourse-cdn.com/v4/letter/f/54ee81/32.png) [@felipe2010silva](https://forum.inductiveautomation.com/u/felipe2010silva)\
**Post date:** [June 23, 2021, 1:57pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/7 "2021-06-23T13:57:55Z")

</div>

Hi @JordanCClark I tested your generic system on a table component, to later use it in my application. but I think I did something wrong. I put the script in propertyChange of a table component. In the end I added the table’s data property to the findData variable and some errors appeared. I will attach them.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/e/5ec581ba42500a2aa177bbfcf4690682836ae6df.png)

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [June 23, 2021, 2:20pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/8 "2021-06-23T14:20:57Z")

</div>

Use the script console (under Tools) to test with. I copy/pasted @JordanCClark code and it worked.

---

<div class="post-metadata">

**Author:** ![felipe2010silva](https://avatars.discourse-cdn.com/v4/letter/f/54ee81/32.png) [@felipe2010silva](https://forum.inductiveautomation.com/u/felipe2010silva)\
**Post date:** [June 23, 2021, 2:34pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/9 "2021-06-23T14:34:33Z")

</div>

I took the test, but the error persists

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/2/720aa629887b6ffedb5b58b4f817424374b9293c.png)

---

<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:** [June 23, 2021, 2:35pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/10 "2021-06-23T14:35:41Z")

</div>

What version of Ignition?

Also, copy the “Caused by:” portion of the error and post it here. 🙂

---

<div class="post-metadata">

**Author:** ![felipe2010silva](https://avatars.discourse-cdn.com/v4/letter/f/54ee81/32.png) [@felipe2010silva](https://forum.inductiveautomation.com/u/felipe2010silva)\
**Post date:** [June 23, 2021, 2:38pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/11 "2021-06-23T14:38:29Z")

</div>

version 7.9.9

`Caused by: java.lang.ClassCastException: org.python.core.PyObjectDerived cannot be cast to org.python.core.PySequence

```
at com.inductiveautomation.ignition.common.script.builtin.DatasetUtilities.toDataSet(DatasetUtilities.java:487)

at sun.reflect.GeneratedMethodAccessor364.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.python.core.PyReflectedFunction. __call__ (PyReflectedFunction.java:186)

... 25 more

```

Traceback (most recent call last):  
File “”, line 30, in   
File “”, line 28, in findEquals  
at com.inductiveautomation.ignition.common.script.builtin.DatasetUtilities.toDataSet(DatasetUtilities.java:487)

```
at sun.reflect.GeneratedMethodAccessor364.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

```

java.lang.ClassCastException: java.lang.ClassCastException: org.python.core.PyObjectDerived cannot be cast to org.python.core.PySequence  
`

---

<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:** [June 23, 2021, 2:42pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/12 "2021-06-23T14:42:16Z")

</div>

Ah, makes sense, then. Written for 8.0+

in the function try these two lines instead:

```auto
	headers = list(datasetIn.getColumnNames())
	dataOut = [list(row) for row in dataIn if row[colName] == value]

```

---

<div class="post-metadata">

**Author:** ![felipe2010silva](https://avatars.discourse-cdn.com/v4/letter/f/54ee81/32.png) [@felipe2010silva](https://forum.inductiveautomation.com/u/felipe2010silva)\
**Post date:** [June 23, 2021, 2:53pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/13 "2021-06-23T14:53:43Z")

</div>

the error was solved, but it doesn’t give me any results. It’s normal?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/2/12790ff83ba1f8c905a5a6d28105f3a8acd3b640.png)

---

<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:** [June 23, 2021, 2:57pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/14 "2021-06-23T14:57:10Z")

</div>

Well, it gave you a dataset. Now, you have to do something with it. 😉

---

<div class="post-metadata">

**Author:** ![felipe2010silva](https://avatars.discourse-cdn.com/v4/letter/f/54ee81/32.png) [@felipe2010silva](https://forum.inductiveautomation.com/u/felipe2010silva)\
**Post date:** [June 23, 2021, 2:58pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/15 "2021-06-23T14:58:46Z")

</div>

It worked here. Thank you so much for all your support.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/9/39680c6b26cee4cca9eb60840ae34a8477e6133c.png)

---

<div class="post-metadata">

**Author:** ![William\_R](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/william_r/32/32710_2.png) [@William\_R](https://forum.inductiveautomation.com/u/William_R)\
**Post date:** [August 23, 2023, 2:47pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/16 "2023-08-23T14:47:55Z")

</div>

Hi Jordan,

I tried your script and it worked flawlessly in the script console. When I move it to a gateway script, it doesn't run. Any idea what could be the issue? TIA.

---

<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 23, 2023, 2:52pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/17 "2023-08-23T14:52:05Z")

</div>

> [@William\_R](#):
>
> When I move it to a gateway script, it doesn't run.

Well, that narrows it down to just about everything.

- Is there an error in the log?
- How are you trying to use it?
- Any sample data you're willing to share, with expected results?

---

<div class="post-metadata">

**Author:** ![William\_R](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/william_r/32/32710_2.png) [@William\_R](https://forum.inductiveautomation.com/u/William_R)\
**Post date:** [August 23, 2023, 3:22pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/18 "2023-08-23T15:22:01Z")

</div>

I am trying to use it in a timer gateway script to look at different clients and count how many times a user is logged in at on a specific PC. It is a timer script.

From Error Log:

* * *

com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 31, in File "", line 24, in findEquals NameError: global name 'system' is not defined

Caused by: org.python.core.PyException: NameError: global name 'system' is not defined

Example code:

* * *

```auto
import system
from java.lang import System

sessions = system.util.getSessionInfo()
def findEquals(datasetIn, colName,value,colName2,value2):
	# Convert to PyDataSet
	dataIn = system.dataset.toPyDataSet(sessions)
	import system
	headers = list(dataIn.getColumnNames())
	dataOut = [row for row in dataIn if (row[colName] == value and row[colName2] == value2)]

	return system.dataset.toDataSet(headers, dataOut)
findData = findEquals(sessions, 'username', 'Lockout','address', 'DESKTOP-XXXXXX')
rowCount = findData.getRowCount()

if(rowCount > 0):
	system.tag.writeBlocking(['[default]LockoutUserRole'], True)

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [August 23, 2023, 3:24pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/19 "2023-08-23T15:24:28Z")

</div>

Gateway event scope bamboozlery.  
Don't write scripts in the gateway event, put them in the script library and call them from the event.  
Don't import system.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [August 23, 2023, 3:25pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/20 "2023-08-23T15:25:32Z")

</div>

> [@William\_R](#):
>
> ```auto
> def findEquals(datasetIn, colName,value,colName2,value2):
> # Convert to PyDataSet
> dataIn = system.dataset.toPyDataSet(sessions)
> import system
> 
> ```

Without line numbers to back me up, this block seems like the culprit as you're trying to import `system` AFTER you've already tried to use it.

---

<div class="post-metadata">

**Author:** ![William\_R](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/william_r/32/32710_2.png) [@William\_R](https://forum.inductiveautomation.com/u/William_R)\
**Post date:** [August 23, 2023, 3:30pm UTC](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101/21 "2023-08-23T15:30:46Z")

</div>

Thanks for your reply. I had the import outside the definition at first, without it inside the definition. Scrambling to try and make it work I thought to actually add it to the definition, as well as "sessions" but copied it to the wrong spot. Stupid error on my part .. its working now. Thank you.

[Next page](https://forum.inductiveautomation.com/t/how-to-return-a-row-and-column-of-specific-data-from-a-dataset/48101.md?page=2)
