How to check for duplicate rows in a particular column without removing duplicates?

I’ve tried to find a solution on the forum but all solutions are for different scenarios.

My case is the following:
I have a MyDataTable with approximately 18.000 rows. Tried to use For Each Row but checking for duplicates that way last for hours.
I need to check if a particular column(column is Serial_Number) contains duplicates.
If there are duplicates, I need to count how many duplicates exist for Serial_Number column.
One more important thing is that I must not delete found duplicates.

Which method do you guys think is the fastest and most effective for my scenario?
Thanks in advance. :pray:

Give a try on following:

prepare an empty reportDataTable with Build DataTable - dtReport
Col: SerialNo, Count

Assign Activity
left Side: dtReport
Right side:

(From d in YourDataTableVar.AsEnumerable
Group d by k=d("Serial_Number").toString.Trim into grp=Group
Let ra = new Object(){k,grp.Count}
Select r=dtReport.Rows.Add(ra)).CopyToDataTable

Total report

In case we want only duplicated SerialNOs within the reportz we can do:

(From d in YourDataTableVar.AsEnumerable
Group d by k=d("Serial_Number").toString.Trim into grp=Group
Where grp.Count > 1
Let ra = new Object(){k,grp.Count}
Select r=dtReport.Rows.Add(ra)).CopyToDataTable
1 Like

Amazing answer, great approach for finding duplicates.

I really appreciate your help, thank you! :pray:

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