How To Remove Duplicates From Datatable In UiPath

Duplicate data is unavoidable and it is not always possible to keep it away.

Sometimes it can be also that we are trying to get distinct values.
So how we do that?

We can use the below LINQ query to achieve it 🙂

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

Note:
1.Useful when we are removing duplicates with respect to some “Column” name
2.Simply replace the “columnWithDuplic” with your required column name

OR

We can use the simple DefaultView Code too…

 

dataTable new_dt =
old_dt.DefaultView.ToTable(True)

Note:
Useful when we are removing duplicates with respect to every “Column”


Example

Implementation using UiPath :

Assume we have a sample data, which includes information about 3 students.

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

UiPath Remove duplicates from Datatable 1.PNG

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

UiPath Remove duplicates from Datatable 2.PNG

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

UiPath Remove duplicates from Datatable 3.png

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

UiPath Remove duplicates from Datatable 4.png

Note: Here we are using the “Name” 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.

UiPath Remove duplicates from Datatable 5.PNG

Step 6:

Final output!!!

UiPath Remove duplicates from Datatable 6.PNG

Click here to download the Source Code…

Hope it has helped you… 

Advertisements

Author: Sharath Raju

Founder@www.ExcelCult.com

Leave a Reply