How to get Duplicate Records Count in Datatable

Hi Team,
I am having two data tables in First data table the column values of EMPID should be compared with second data table EMPID column values if there is any duplicate matching get the count and print the count

Ex:First Dt : EMPID
1
2
3
4

Ex: second Dt :EmpID
1
2
1
2
3

Result :EmpID Count
1 2
3 1
2 2

Regards
A Manohar

Kindly refer to the below link. Hope this helps.

Thanks,
AK

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

Hi @Manohar1

Use this

New dt= (from p in dt.Select() where( From q in dt.Select() where string.Join(",",q.ItemArray).Equals(string.Join(",",p.ItemArray)) Select q).ToArray.Count>1 Select p).ToArray.CopyToDataTable()

Check dt.rows.count.ToString

Hi @Manohar1

Have a look here,

1 Like