Want to remove duplicates names from single column from datatable

image

Want to remove duplicate names . please suggest how to do ?

Hi @sushama.mundhe

You can use the following query in the Assign activity:

yourDataTable = yourDataTable.DefaultView.ToTable(True,"Name")

This will remove the duplicate entries based on the ‘Name’ column.

Hope this helps,
Best Regards.

Hi @sushama.mundhe ,

We see that Even though the name are duplicates, the Task and the Hour columns are different. So we do not know yet what is the preference row to be preserved and what is the row to be removed and based on what condition.

If you could provide an Expected Output for the Input provided we would be able to help you better.

Hi @sushama.mundhe

Please try this-

myDataTable.AsEnumerable().Select(Function(x) x.Field(Of String)(“Name”)).Distinct()

Thanks!

This works but other columns get removed , need rest of the column also.

Need only first entry of the name and if other similar name found , then it should get deleted.

@sushama.mundhe

As your data contains one-to-many mapping, i.e., One name has different Task & Hours data, you need to specify in which manner you want to filter the data. It depends on your use case whether you want to remove the entire row based on the duplicate name or merge the duplicate names keeping the remaining data intact.

Can you please share the expected output, so that we can analyze your requirements thoroughly?

Best Regards.

@sushama.mundhe

Welcome to the community

Please try this in assign activity

Outputdt = dt.AsEnumerable.GroupBy(function(x) x("Name").ToString ).Select(function(x) x.First).CopyToDataTable

Dt is the input datatable where the data from excel is present

Outputdt is the output as you required…can write it to excel using write range

Cheers

It works, Thanks community for help.

1 Like