How To Remove Duplicates From Datatable In UiPath

Mostly we find duplicates in our excel file/Datatable and it is unavoidable.

In this article we will see how we can find the distinct values. There are many ways to do the same.

Here, we will use the LINQ Query to achieve the result.

dataTable new_dt =
old_dt.AsEnumerable().GroupBy(Function(i) i.Field(Of String)(“columnWithDuplicate”)).Select(Function(g) g.First).CopyToDataTable

The above LINQ query is useful when we are removing duplicates with respect to some “Column” name.

OR

We can use the simple DefaultView Code too…

dataTable new_dt =
old_dt.DefaultView.ToTable(True)

It is useful when we are removing duplicates with respect to every “Column”

Example

Implementation using UiPath :

Assume we have a sample data, which includes supplier information.

Step 1:
Drag a “Build Data Table” activity into the design panel.

image

Step 2:
Populate the “Build Data Table” activity with sample data.

image

Step 3:
Create a variable of DataTable type with some name and supply it to the Output property of “Build Data Table” activity.

image

Step 4:
Drag “Assign” activity into the design panel and in the “Value” property of that activity use the above code with proper values

image

Note: Here we are using the “Supplier Number” column to remove the duplicates from the data table.

Step 5:
Drag “Output Data Table” and “Message Box” activity into the design panel and supply the appropriate parameters to display the data.

image

Step 6:

Final output!!!

image

I hope you like the article.

Happy Automation !!