Filtering data table more quickly

Hi,

I read in an excel sheet that is very large and i want to filter the rows based on a string (filteredValue). This method works but takes several minutes to execute due to the size of the data table i presume. is there a faster way to do this?

New to UiPath so thanks for the help

@tREX
Welcome to the forum

you can try if it is faster:
Assign Activity
Left side: dtFiltered - datatype: Datatable
right side:

yourDTVar.AsEnumerable.Where(Function (x) x("Column0").toString.Contains(filteredValue)).CopyToDatatable

In case of the risk of empty filter results apply following pattern:

1 Like

Hi, Thanks for the help. not sure if i am doing it correctly. see below.

@tREX
just do directly with adopted variable names:

Variables
drFiltered - List (Of DataRow)
dtFiltered - Datatable

Assign:
drFiltered =
dt_DCMaster.AsEnumerable.Where(Function (x) x(“Column0”).toString.Contains(filteredValue)).toList

if Activity
then: dtFiltered = drFiltered.CopyToDataTable
else: dtFiltered = dt_DCMaster.Clone

thats all

Hi @tREX

Welcome to Forum.

Check the above link, it explains 4 different ways to filter a data table.

Thanks,
Jiban

Hi again,

So i tried as you said but it is showing no matching rows even though there are.

The filterderValue String is “Birdwatch” which is one of the first rows shown below

@tREX
can you please crosscheck this part:
x(“Column0”).toString.Contains(filteredValue)

Okay that is working well now. Thank you very much.

Would i need the empty filter results part at all so?

Didn’t get you.
CopyToDataTable throws an exception if the filter statement is empy and returns no rows. Thats why we do apply this pattern in case of we cannot rely on a mandatory non empty filterresult

Thanks again. Just one last question. How to compare the data table to the string without upper case or lower case affecting the resulting filter?

Are you looking for a canse insensitive filtering?
give a try on
x(“Column0”).toString.toUpper.Contains(filteredValue.toUpper)

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.