How to get Duplicate Records Count in Datatable

Hello.

So, it seems you just want to know how many from the first table is also in the second table.

You can probably run the first table through a For Each loop, then calculate the matches.

I, personally, would probably use some .net to pull in the matches. A pseudocode for this would look like this:

If Not dt1.Columns.Contains("Count")
    Add Data Column "Count"

For each row In dt1
    Assign count = dt2.AsEnumerable.Where(Function(r2) r2("EmpID").ToString.Trim = row("EmpID").ToString.Trim).ToArray.Count
    Assign row("Count") = count.ToString

Note: this is not actual code and just showing the activity logic needed in UiPath

When calculating the count, I was comparing the values as strings, so if you need to compare them as numbers which is common, you will need a slightly different condition to convert the values to numbers first.

Regards.

1 Like