Filter a data table if contains

Hi everyone!

I need to filter a datatable if the column “result” cointains the string “ok”.

How can i do?

Thank you

Hey @Siltra,

You can use filterDataTable activity :slight_smile:
Just fill in the appropriate values

!

1 Like

I update all my packeges but I dont’t have this activity :frowning:

Is it possible by select method?

It should be under Data Table heading in the activities column!!

this is what I have…

That’s a bit weird.There should be like 10 more activities there!

Anyways, you can do it with select too…but still you’ll require Add Data Column activity which i again don’t see there!
Try reinstalling the UiPath.Database.Activities package…It’ll be difficult to work without those activities!
Should look like this!

I have Add Data Column Activity. How can I use this to filter data table?

image

Hello @Siltra,

Please refer to the workflow i created for you :slight_smile:
So what we can do is use select to get the data rows that have result column value ‘ok’
Select returns an array of data rows.
Then we can build a new datatable and through foreach and add data row add the filtered rows in the new data table!Main.xaml (11.3 KB)

Thank you very much for your helping, but the I need rows where column result CONTAINS the string ok, so I can’t use equals operation.

Because you need a contains and not an equal to, I would build a second datatable and loop through the first. Each time it comes across a value containing “OK”, add that row to the second datatable.

So is not possible to do it without a loop only using the select method? I just to count the number of rows, so I don’t need to build the data table after this operation.

Hi @Siltra, the filter data table options are available in version 2018.2.0. May be try to install the latest version. It might work. .!!

Thanks…!!

Hey @Siltra,

You can try using dt.Select(" result=‘* ok *’ " )
it will get you the rows having
sometext(space)ok(space)sometext

3 Likes

Hi - You can filter the DataTable like this.

here outDt is a dataTable Variable.

Thank you,
Nitesh

@Siltra
I tried using dt.Select(“result LIKE ‘%ok%’”)
Works just fine! :slight_smile:

1 Like

HI,

I am trying to filter a data table using .Select() but i want to use the column index rather than the column name; how do i go about it

Hi @Odunayo_Ogundepo,

Try below code to filter using column index
dataTable.Select("[" + dataTable.Columns[ColumnIndex].ColumnName + "] = 1")

Regards,
Arivu :slight_smile:

Thanks @arivu96

But i meant my column does not have a name. The only reference i have are the Column letters on the worksheet or the index.

for instance data.Select("[Status]= 'PV'"). this code selects all the rows who’s status column is PV.
I need a code that uses the column index instead of the column name

Thank you.

Hi @Odunayo_Ogundepo

Try below code
(from dr in DT1 where dr.item(1).contains ("PV") select dr).ToArray().CopyToDataTable()

Regards,
Arivu :slight_smile:

1 Like

Hello!

Can I simply use a filter data table activity to filter a data table for result coloumn which contains “success” Currently this filter is not able to filter the table.

can I use the operator contains? sharing the screenshot.
image