Filtering Dataset using expression binding

Hello, there is function that I can use on EXPRESSION Binding
to get 2 first row of dataset ?

For exemple, I have :
image

What I want to show is:
image

Not directly. The Expression Language dataset operations are limited.

https://docs.inductiveautomation.com/display/DOC81/Expression+Language+and+Syntax#ExpressionLanguageandSyntax-DatasetAccess

You could script a transform on the data binding.

def transform(self, value, quality, timestamp):
	pyDs = system.dataset.toPyDataSet(value)
	headers = system.dataset.getColumnHeaders(value)
	data = [pyDs[0], pyDs[1]]
	return system.dataset.toDataSet(headers, data)

If I don't mention it, Phil will be along to remind me that you should put the script in the Project Library and call it using the Expression Language runScript() function.

1 Like

Thank you @Transistor I'am using VISION, I think I can't do transform script into vision :face_with_open_eyes_and_hand_over_mouth:

Yes, in my Integraton Toolkit module. The where() expression function, in particular.

If you just want specific row indices, like the first two rows, use idx() in the condition, like so:

where({path.to.source.dataset}, idx() < 2)

If you actually want to check the content, like matching the 3-letter prefix on ProductCode, you'd do something like this:

where({path.to.source.dataset}, left(it()['ProductCode'], 3) = 'BAN')
3 Likes

You need to add the Vision tag to your question.

1 Like

That is mean if I want show 20 values of rows, I must repeat this line 20x ?

Also look at the transform() function. :laughing:

1 Like

Yes, using data.append() in a for loop.

...but you can, using a custom property for your untransformed binding and a propertyChange script to transform any new value before it's assigned to the actual property.

pyDataSet supports slicing, so if he just wants the first 20 items, he can use pyDs[:20].

4 Likes

Or... what exactly are you filtering for? Specific data? A specific number of rows? If we know that info we can help. Your original post looked like the top 2 rows... so that was the example.

So backup and tell us the constraints for filtering the dataset.

3 Likes

hello @bschroeder I have found solution using idea suggested by @pascal.fragnoud and @Transistor.

Normally what I was searching is filtering somme rows of dataset instead to show all of then.

I recently installed the ingration toolkit. For functions like where() or leftJoin() how can I pass a query result to the expression? I've tried putting db.runQuery scripts in to your {path.to.source.dataset} but can't seem to get that to work. However, I've successfully used them when referencing tags that query the data, but I feel like I should be able to directly use the query in the expression...

Expressions ≠ Scripts.

If you have a query or historian binding supplying data to a component property (likely a custom property), you can reference that property in an expression binding (not a script).

If you have objects in scripts, use the scripting functions my module supplies. If you have objects in UI properties, use the expression functions my module supplies.