Query against another object dataset

Thanks for all the help I’ve gotten already by browsing the forum, but I couldn’t find an answer to this one:

Is there a way to run a query or otherwise access the data in a dataset that is displayed in a table?

I have a table which runs a query to display Cycle times for the operator, and I would like to also display some statistics regarding the data on that table, Average, Max / Min etc.

I could have another query against the database using the same parameters but returning the average or Min / Max, but it would seem to be more efficient to not require another query against the db.

Thanks in advance

Hi tdornbush,

This sort of thing is easily done in a Python script. You could create a Python script that runs during a propertyChange script or other event.

Here’s some example code that gets the average and max values from columns in a table and then sets labels to display those values:

table = event.source.parent.getComponent("Table")
co1AverageList = []
col3Max = 0

for row in system.dataset.toPyDataSet(table.data):
	co1AverageList.append(row["Col 1"])
	col3Max = max(col3Max,row["Col 3"])

col1Average = sum(co1AverageList) / len(co1AverageList)

event.source.parent.getComponent('Average Label').text = "Average: %s"% col1Average
event.source.parent.getComponent('Max Label').text = "Max %s"% col3Max 	

You might want to study the Scripting course on Inductive University: inductiveuniversity.com/course/scripting


If your requirements are simple, you could just use the expression functions in the ‘Aggregates’ section to access the ‘data’ property of the table. The most common operations are supported. You might want to start here.

I should be able to make one of those solutions work.

Hi tdornbrush,
Your question was part of the inspiration for the view() expression function in the beta Simulation Aids module. You might want to take a look at it. In this particular case, a “Group By 0” clause would allow you to apply aggregate functions to all of the source rows in your table.

I haven’t taken a look at the Simulation Aids yet, but I used Phil’s suggestion of expression bindings and it worked well.

I made a table of averages (a single row) below my main table. I added custom properties to the ave table, one for each column, and used the expression “mean({dataset},col)” to bind them to columns in my main table.

Then I bound the newly populated custom properties to my ave table’s cells using cell update bindings.