How to remove duplicate values in a specified column in a datatable?

Hi UiPath,

I need help with my project.

let say I have the excel file below:

My goal is to remove the duplicate values in column “Purchasing Document”.

I want to retain the unique values only on each row for column Purchasing Document.

Hope someone can help me.

Thanks!

you can use remove duplicate rows activities and provide your datatable in that

or use

distinctRows = dtData.AsEnumerable() _
.GroupBy(Function(row) row.Field(Of String)(“Purchasing Document”)) _
.Select(Function(group) group.First()) _
.CopyToDataTable()

Regards

@alvin.c.apostol26

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

or

Assign activity:
NewDataTable = (From row In YourDataTable.AsEnumerable()
Group row By ColumnName = row(“YourColumnName”)
Into Group
Select Group(0)).CopyToDataTable()

1 Like

Hey @alvin.c.apostol26 ,
After read range you get a datatable as output
Then add an assign activity and at Right side write :Dt.AsEnumerable.Distinct(function(row) row("Purchasing Document")).CopyToDatatable
Left side assign the same Datatable variable

Hi @alvin.c.apostol26

Use Remove Duplicates Row activity
Or

DataTable=DataTable.AsEnumerable.Distinct(function(a) a(“Purchasing Document”)).CopyToDatatable

I hope it helps!!

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