# Problem to filter dataset

**URL:** <https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140>\
**Category:** Ignition\
**Created:** [July 31, 2023, 1:45pm UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140 "2023-07-31T13:45:52Z")\
**Posts on this page:** 20\
**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:** [July 31, 2023, 1:45pm UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/1 "2023-07-31T13:45:52Z")

</div>

Hello I have this dataset:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/5/7546dfe143beaf7ad3eff3c39ad62bc03863ad31.png)  
And I would like filtering row of my dataset where zone =A

I want obtain this data below :  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/5/e5688ca21fb5a2e0c0654e09ca5c2bd417bd7224.png)

how can I filtering it please.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 31, 2023, 1:46pm UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/2 "2023-07-31T13:46:36Z")

</div>

Is this Vision or perspective? Where is the dataset coming from?

---

<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:** [July 31, 2023, 2:16pm UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/3 "2023-07-31T14:16:49Z")

</div>

```python
def filter_dataset(ds, condition):
	return system.dataset.toDataSet(list(ds.columnNames), filter(condition, system.dataset.toPyDataSet(ds)))

filter_dataset(ds, lambda row: row['zone'] == 'A')

```

---

<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:** [July 31, 2023, 2:26pm UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/4 "2023-07-31T14:26:11Z")

</div>

Thank you, pascal for your anwser. How can whrite without use function please

---

<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:** [July 31, 2023, 2:27pm UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/5 "2023-07-31T14:27:13Z")

</div>

> [@sebastien\_ng](#):
>
> How can whrite without use function please

Why?

Please explain what you are trying to do.

---

<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:** [July 31, 2023, 2:31pm UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/6 "2023-07-31T14:31:04Z")

</div>

I want use something like

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/a/0a7838505bc27d413b6f7507c0d035b01637b746.png)

I don't want use function beacause I wand return this dataset on Scrit Transformation this why I don't need use function.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [July 31, 2023, 2:34pm UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/7 "2023-07-31T14:34:30Z")

</div>

put the filter function in your project scripts library  
[https://docs.inductiveautomation.com/display/DOC81/Project+Library](https://docs.inductiveautomation.com/display/DOC81/Project+Library)

---

<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:** [July 31, 2023, 2:35pm UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/8 "2023-07-31T14:35:06Z")

</div>

it work but there is two function on the Script transformation

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/f/afd6a5e1dba029cdab2092d40da37b7bbca31543.png)

---

<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:** [July 31, 2023, 2:36pm UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/9 "2023-07-31T14:36:32Z")

</div>

Thank you Victor I juste have so much function there that is why I don't nedd put there.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 31, 2023, 2:39pm UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/10 "2023-07-31T14:39:29Z")

</div>

You can nest functions in Python. It's fine. You also don't have to encapsulate it as a function:

```python
def transform(self, value, quality, timestamp):
	return system.dataset.toDataSet(
		list(value.columnNames),
		filter(lambda row: row['zone'] == 'A', system.dataset.toPyDataSet(ds))
	)

```

---

<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:** [July 31, 2023, 2:43pm UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/11 "2023-07-31T14:43:00Z")

</div>

> [@paul-griffith](#):
>
> ```auto
> return system.dataset.toDataSet(
> list(value.columnNames),
> filter(lambda row: row['zone'] == 'A', system.dataset.toPyDataSet(ds))
> )
> 
> ```

Thank you very much, this suits me better

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 31, 2023, 3:04pm UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/12 "2023-07-31T15:04:25Z")

</div>

> [@sebastien\_ng](#):
>
> Thank you very much, this suits me better

Honestly, it looks suspiciously like you'll be utilizing this function in multiple places. You really should generalize it further so that you only have to maintain it in one place (Project Script Library).

I would suggest this:

```python
def filterDataset(ds,columnName,filterValue):
    return system.dataset.toDataSet(
        list(ds.columnNames),
        filter( lambda row: row[columnName] == filterValue,
            system.dataset.toPyDataSet(ds))
    )

```

Then your transform for say Zone B would look like:

```auto
def transform(self,value,quality,timestamp):
    return projectLibrary.filterDataset(value,'zone','B')

```

---

<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:** [July 31, 2023, 3:09pm UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/13 "2023-07-31T15:09:16Z")

</div>

Or maybe an expression binding instead of tag binding? No transform at all. Like this:

```auto
where({[AR]A-VMS/camAdresse}, it()['VOIE'] = 'A')

```

Via my latest [Simulation Aids](https://inductiveautomation.com/moduleshowcase/module/automation-professionals-llc-simulation-aids) (free!).

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 31, 2023, 3:10pm UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/14 "2023-07-31T15:10:20Z")

</div>

Or `system.dataset.filter` from [Ignition Extensions](https://forum.inductiveautomation.com/t/ignition-extensions-convenience-utilities-for-advanced-users/64615), as long as we're plugging modules 🙂  
Phil's is going to be faster, though.

---

<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:** [August 1, 2023, 8:38am UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/16 "2023-08-01T08:38:58Z")

</div>

Hello, thank you for all your proposition. This help me so much to filter my data.  
But I have Other question.  
If I want get index of row were value of column table = 5, how can I do it.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/7/57728b67e67fe7568db6c357b8bc75c829372ab2.png)

---

<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 1, 2023, 8:59am UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/17 "2023-08-01T08:59:18Z")

</div>

```python
column_index = ds.getColumnIndex('table')
column_values = ds.getColumnAsList(column_index)
index_of_five = column_values.index(5)

```

or, to make things simpler:

```python
def find_in_ds(ds, column, value):
	return ds.getColumnAsList(ds.getColumnIndex(column)).index(value)

find_in_ds(ds, 'table', 5)

```

But why, though ? Why do you need the index ? What are you trying to do ?  
If you want to retrieve values from a particular row in a dataset, the `lookup` expression functions is what you want:  
[https://docs.inductiveautomation.com/display/DOC81/lookup](https://docs.inductiveautomation.com/display/DOC81/lookup)

---

<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:** [August 1, 2023, 9:47am UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/18 "2023-08-01T09:47:11Z")

</div>

I have filtered a dataset and I would like to find index of each row value , that is why I need the index

---

<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 1, 2023, 9:48am UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/19 "2023-08-01T09:48:04Z")

</div>

That doesn't tell me why you want the index.

> **[The XY Problem](https://xyproblem.info/)**
>
> Asking about your attempted solution rather than your actual problem

---

<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:** [August 1, 2023, 10:06am UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/20 "2023-08-01T10:06:28Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/6/761651916e3abdf6530ee456d35f0560f6739abf.png)

I have a webcam set on a Vue.  
Each webcam has an url address and an ID  
I have a vCam view  
On this view, I have a dataset on CUSTOM .  
On the vCam View , I have an ID parameter, and pCount

pCount must get the index of the table ID set on parameter

And I I send the dataset, ID and pCount in a Popup

Each webcam Have a Popup, when user clique on an webcam, I want kown index row of url ou ID on the dataset.

---

<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:** [August 1, 2023, 12:29pm UTC](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140/21 "2023-08-01T12:29:50Z")

</div>

> [@sebastien\_ng](#):
>
> On the vCam View , I have an ID parameter, and pCount

Consider passing the whole row of the dataset as one parameter into the popup view.

[Next page](https://forum.inductiveautomation.com/t/problem-to-filter-dataset/77140.md?page=2)
