# How to count duplicate value in each column

Hi Guys,

I want below output , please anyone help this

Regards,
Raja G

Good evening Raja,

Iâ€™m not sure what exactly youâ€™re calculating in the â€śRepeat_Countâ€ť column.

Would you mind clarifying what youâ€™re looking for?

Some values appear to get the count of the age for different rows (45 count is 2) and others appear to count the name of other rows (Kartik â†’ Ross count = 3). It looks very sporadic overall.

Yeah its my manual mistake only, I need just a count of duplicate values and output to show in new column.

Regards,
Raja G

Hey @Raja.G

You will need to create a â€śpivot tableâ€ť which gives you the repeat count and then join the data in your input datatable.

The steps are described below:

Create variables:
tempObj - object type
dtDuplicates - 2 column(string type) dt - â€śCheckDupâ€ť
and â€śRepeat_Countâ€ť
dtJoin - 3column(string type) dt - â€śCheckDupâ€ť, â€śAgeâ€ť,â€ťRepeat_Countâ€ť

Step 1 - populate dtDuplicates

tempObj = dtInput.AsEnumerable.GroupBy(function(x) x(â€śCheckDupâ€ť).ToString).Select(function(y) dtDuplicates.Rows.Add(New Object() {y.Key, y.Count.ToString})).CopyToDatatable

Step 2 - join dtInput with dtDuplicates

tempObj =
(From R In dtInput.AsEnumerable
Join L In dtDuplicates.AsEnumerable
On R(â€śCheckDupâ€ť) Equals L(â€śCheckDupâ€ť)
R(â€śCheckDupâ€ť),
R(â€śAgeâ€ť),
L(â€śRepeat_Countâ€ť)
})
).CopyToDatatable

2 Likes

Thanks for points , but i didnâ€™t understand below variables , please can u elaborate

Create variables:
tempObj - object type
dtDuplicates - 2 column(string type) dt - â€śCheckDupâ€ť
and â€śRepeat_Countâ€ť
dtJoin - 3column(string type) dt - â€śCheckDupâ€ť, â€śAgeâ€ť,â€ťRepeat_Countâ€ť

Regards,
Raja G

You have to create those variables in the first place.

Variable name: tempObj
Variable type: Object

Variable name: dtDuplicates, dtJoin
Variable type: datatable

Use Build datatable to add the required columns - as mentioned in the post before.

For Step 2, you may also use Join Datatables activity from UiPath, if you are more comfortable this way.

1 Like

Thanks again, sorry for the update, â€śRepeat_Countâ€ť column just a output column , i need to show the output to next sheet in same excel, because i want more columns duplicate values , can u help this

Regards,
Raja G

If you only follow Step1, a datatable with duplicates will be generated. You can output that wherever you need it.

You can use it for computing duplicates also from other columns.

1 Like