Filter rows where a column has numbers in DataTable

While creating a business process automation we will use a lot of DataTables.

Sometimes the provided input for the bot might be excel and it needs to be filtered before processing.

Let’s say the input is excel and in a particular column it has mixed values i.e,(a combination of numbers, special characters, and alphabets) but it needs to process the rows that have only numbers.

In this article, we discuss how we can filter rows where a column has numbers in DataTable using UiPath.

Let’s jump into the practical implementation of this task:

Step1: Drag and Drop a Build DataTable Activity from the activities panel to the designer panel and create a DataTable as shown below:

build datatable

In the above DataTable, it is evident that the Code column has different values with a combination of numbers, special characters, and numbers.

Step2: Create a new DataTable variable in the variable panel to store the filtered rows.

There are two different approaches to achieve this task. They are mentioned below:

  • Using For each row in DataTable
  • Using LINQ Query

Using For each row in DataTable:

Step3: Drag and Drop an assign activity from the activities panel to the designer panel and clone the main DataTable headers to the new DataTable as shown below:

clone datatable

If you want to know more about how clone works take a look at this article:

Step4: Drag and Drop for each row in DataTable activity from the activities panel to the designer panel as shown below:

filter rows where a column

Step5: Drag and Drop If activity from the activities panel to the designer panel and Add Data Row Activity inside then of If condition as shown below:

filter rows where a column

Here:

Microsoft.VisualBasic.Information.IsNumeric(Currentrow("Code").ToString)

This line of code checks whether that value has only numbers or not.

Then we are adding those Datarows to a new DataTable which is already created earlier in step2.

Using LINQ Query:

Step6: Drag and Drop an assign activity from the activities panel to the designer panel and enter the code as shown below:

filter rows where a column

Here:

The above code is used to filter rows where a column has only numbers in DataTable.

Step7: Drag and Drop output DataTable activity from the activities panel to the designer panel to see the output of the new DataTable as a string.

Step8: The output of the above two methods is shown below:

output datatable

Happy Learning!

Like this post then let your friends know about this-:

Leave a Reply

Your email address will not be published. Required fields are marked *