I have this datatable with 8 columns. Column 1 is ID(Unique) and Column 6 is Name.
For all the values in the table. I want to Check if the row value of Column 1 and Column 6, is the same with any row in the table. If Yes, remove all duplicates. I tried using Remove Duplicate rows activity, but then some rows that have the same value in Column 1 and 6, has a different value for Column 3.
I tried dt.DefaultView.ToTable(true, "ID","NAME")
although this works, it also removed the other 6 columns.
Dup.xlsx (16.0 KB)
Take this as an example. The column “ID” and “Name” is what I’m trying to check for duplicate. I can’t use remove duplicate rows here as some columns(Date and Item) has a different value.
Hi @Shinjid ,
Do you want to eliminate just the duplicates or remove those entries which contain duplicates completely?
If its the former, then this ought to do the trick:
Dt_sampleData.AsEnumerable().GroupBy(Function(g) Tuple.Create(g("ID").ToString,g("Name").ToString)).Select(Function(s) Dt_sampleData.Clone.LoadDataRow(s.First().ItemArray,False)).CopyToDataTable()
And if its the former then this is the code that will help you out with that:
Dt_sampleData.AsEnumerable().GroupBy(Function(g) Tuple.Create(g("ID").ToString,g("Name").ToString)).Where(Function(w) w.Count=1).Select(Function(s) Dt_sampleData.Clone.LoadDataRow(s.First().ItemArray,False)).CopyToDataTable()
RemoveDuplicateRowsBasedOnColumns.xaml (6.8 KB)
Kind Regards,
Ashwin A.K
Thank you very much! This worked on mine. I used Dt_sampleData.AsEnumerable().GroupBy(Function(g) Tuple.Create(g("ID").ToString,g("Name").ToString)).Select(Function(s) Dt_sampleData.Clone.LoadDataRow(s.First().ItemArray,False)).CopyToDataTable()
As I only need the “ID” and “Name” for Comparison
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.