DataTable.select() versus FilterDataTable activity

Hello,

1)Can you please explain the difference between DataTable.select() and filter Data table activity ? When to prefer each and what is more efficient?, as of now I know one difference i found is return type.It would be great if you attach workflows for corresponding

2)And also how to use Datatable.select type for string type of columns in data table
I have given like this
image
getting issue
image

Thanks in advance.

1 Like

Hi.

I’m probably not the best to answer since I have not used the Filter Data Table all that much but have looked at it.

The problem I have with the activity is that you cannot verify and convert values during your condition phases. Like if you wanted to make sure the value is compared as a double, you couldn’t simply place in some syntax to say:
If(IsNumeric(row(0).ToString.Trim),CDbl(row(0).ToString.Trim,0) = value

Another problem I have with it is that you can only output to a DataTable, so if you want to process or update certain rows while keeping the original data table, you can’t really do that.

So,
I’d say the benefit you get from using .Select() is that you can be more flexible in what you are trying to do.

However, I still prefer the lambda method using .Where() for filtering data, and the coding is lot easier to understand… atleast to me. It accomplishes the same as using .Select() for filtering, but if you want to use all the vb.net methods like .Contains, .StartsWith, et cetera it’s fairly simple to do so whereas with the .Select() method for filtering you need to use different syntax. EDIT: Ideally, I would want an activity that is flexible like that where you can output to an array of rows or new data table, and also am able to place vb.net coding embedded in the activity on both sides of the comparison… or maybe there is a better way to make it user-friendly that can check if the value is a number and convert, etc.

The “Cannot find column” error is most likely happening because your data table was not read in with Column Headers or the Header does not exist. I would check the Read Range or Read CSV and make sure AddHeaders is checked. Also, using Output Data Table you can output the table to a message box to verify that the headers are there correctly.

Regards.

2 Likes

Datatable.Select() is not an activity. It is a part of .net framework and returns an array of DataRow objects. It can used in any version of Uipath. While Filter Data Table is activity of UiPath and it is available starting with UiPath version v2018.2.x and its output is DataTable.

6 Likes

Hi,

I am using build data table then using select , facing the same issue.
selectDemo.xaml (9.4 KB)

Issue:
image

Please help me on it, how I can resolve this issue

Thanks,
Karthik

@karthik_bethi you have missed single quote in statement. Use following

dt.Select(“lastname=‘gautham’”)

2 Likes

I will try to summarize it very simply.

  1. Filter Data Table activity works very well with STRING type data.
  2. If you use Filter Data Table activity then you cannot play with type conversions. Also if you want to filter using conditions on multiple columns that too of different type, the output will be not the expected one. For example, you want to filter the data from excel/csv with condition like:
    Age >30 and Gender = “MALE” and Height >5.5
    For this situation to achieve this you have to use multiple Filter Data Table activity, one after another in a sequence

Instead, a simple way is to

  1. Use Excel Application Scope
  2. Use Read Range activity
  3. Use Assign activity,
    image
    var_customDT = var_DT_client126.Select("Age > 30 AND Gender = ‘MALE’ AND Height > " + var_height).CopyToDataTable

Note : var_DT_client126 is the name of my data table and var_height is a variable holding height value and var_customDT is the variable that will hold the output of select statement & its type is DataTable

So, as you can notice in a single line we are able to filter the complete data

4 Likes

Hi ujjwal_gupta
with this assign activity and the select code I am not able to extract the data.
can u pls help me on this.
attaching the flow below

thanks

DataTableAutomation1.xaml (11.9 KB)
strData1.xlsx (13.3 KB)

DataTableAutomation1.xaml (7.9 KB)

1 Like

what would be the expression if all the condition are provided using different argument.
I am getting error using this
var_customDT = var_DT_client126.Select(“Age >” +in_age+" AND Gender =" +in_gender+" AND Height > " + var_height)

When using Select, the return value will be DataRow(), not DataTable
To convert to DataTable, you have to use CopyToDataTable, but the library of this method cannot be imported via Studio. you have to open the xaml and edit manual