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

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

Thank You

I would use the view() expression function from my Simulation Aids module.

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

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

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

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

# 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:

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

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.

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

I took the test, but the error persists

What version of Ignition?

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

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
`

Ah, makes sense, then. Written for 8.0+

in the function try these two lines instead:

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

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

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

1 Like

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

2 Likes