# Filtering Dataset using expression binding

**URL:** <https://forum.inductiveautomation.com/t/filtering-dataset-using-expression-binding/82949>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [December 10, 2023, 8:29pm UTC](https://forum.inductiveautomation.com/t/filtering-dataset-using-expression-binding/82949 "2023-12-10T20:29:01Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [December 10, 2023, 8:29pm UTC](https://forum.inductiveautomation.com/t/filtering-dataset-using-expression-binding/82949/1 "2023-12-10T20:29:01Z")

</div>

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

For exemple, I have :  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/1/514f5eb8d026245a81c395fafcd8b8d08dbd17d0.png)

What I want to show is:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/5/255e83eb3378c838d19b4d38ef9cb800c6fc18a4.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 10, 2023, 8:59pm UTC](https://forum.inductiveautomation.com/t/filtering-dataset-using-expression-binding/82949/2 "2023-12-10T20:59:14Z")

</div>

Not directly. The Expression Language dataset operations are limited.

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

You could script a transform on the data binding.

```auto
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.

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [December 10, 2023, 9:01pm UTC](https://forum.inductiveautomation.com/t/filtering-dataset-using-expression-binding/82949/3 "2023-12-10T21:01:51Z")

</div>

> [@Transistor](#):
>
> script a transform

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

---

<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:** [December 10, 2023, 9:02pm UTC](https://forum.inductiveautomation.com/t/filtering-dataset-using-expression-binding/82949/4 "2023-12-10T21:02:55Z")

</div>

Yes, in my [Integraton Toolkit](https://forum.inductiveautomation.com/t/automation-professionals-integration-toolkit-module/74934) module. The [where()](https://www.automation-pros.com/toolkit/doc/iteration.html#where) expression function, in particular.

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

```auto
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:

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

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 10, 2023, 9:03pm UTC](https://forum.inductiveautomation.com/t/filtering-dataset-using-expression-binding/82949/5 "2023-12-10T21:03:08Z")

</div>

You need to add the Vision tag to your question.

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [December 10, 2023, 9:03pm UTC](https://forum.inductiveautomation.com/t/filtering-dataset-using-expression-binding/82949/6 "2023-12-10T21:03:10Z")

</div>

> [@Transistor](#):
>
> `data = [pyDs[0], pyDs[1]]`

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

---

<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:** [December 10, 2023, 9:06pm UTC](https://forum.inductiveautomation.com/t/filtering-dataset-using-expression-binding/82949/7 "2023-12-10T21:06:13Z")

</div>

> [@sebastien\_ng](#):
>
> can't do transform script into vision

Also look at the [transform()](https://www.automation-pros.com/toolkit/doc/utility.html#transform) function. 😆

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [December 10, 2023, 9:17pm UTC](https://forum.inductiveautomation.com/t/filtering-dataset-using-expression-binding/82949/8 "2023-12-10T21:17:56Z")

</div>

> [@sebastien\_ng](#):
>
> I must repeat this line 20x?

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

---

<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:** [December 11, 2023, 5:31am UTC](https://forum.inductiveautomation.com/t/filtering-dataset-using-expression-binding/82949/9 "2023-12-11T05:31:51Z")

</div>

> [@sebastien\_ng](#):
>
> I think I can't do transform script into vision

...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.

---

<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:** [December 11, 2023, 8:25am UTC](https://forum.inductiveautomation.com/t/filtering-dataset-using-expression-binding/82949/10 "2023-12-11T08:25:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [December 11, 2023, 1:48pm UTC](https://forum.inductiveautomation.com/t/filtering-dataset-using-expression-binding/82949/11 "2023-12-11T13:48:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sebastien\_ng](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sebastien_ng/32/55297_2.png) [@sebastien\_ng](https://forum.inductiveautomation.com/u/sebastien_ng)\
**Post date:** [December 11, 2023, 5:37pm UTC](https://forum.inductiveautomation.com/t/filtering-dataset-using-expression-binding/82949/12 "2023-12-11T17:37:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nate\_macs](https://avatars.discourse-cdn.com/v4/letter/n/b5ac83/32.png) [@nate\_macs](https://forum.inductiveautomation.com/u/nate_macs)\
**Post date:** [October 16, 2024, 7:52pm UTC](https://forum.inductiveautomation.com/t/filtering-dataset-using-expression-binding/82949/13 "2024-10-16T19:52:26Z")

</div>

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...

---

<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:** [October 16, 2024, 8:05pm UTC](https://forum.inductiveautomation.com/t/filtering-dataset-using-expression-binding/82949/14 "2024-10-16T20:05:15Z")

</div>

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.
