Find all values associated to duplicate rows in DT

Hello friends,

Hoping someone has an idea on how to tackle this: My goal is to find only duplicate values in one column of a DT and return their respective values assigned to them.
I hope if anything the screenshot below can better explain.

image

thank you in advance for your time!

Here you go
hope this expression would help you resolve this
datatable = datatable.AsEnumerable().GroupBy(Function(a) a.Field(of string)(“yourcolumnnname”).ToString).Select(Function(b) b.First()).CopyToDatatable()

Cheers @efleurent

3 Likes

Thanks a lot, worked great @Palaniyappan :slight_smile:

1 Like

Hi, what do you mean that worked great? The way i see that expression will just remove the duplicates from the first datatable…

Hi there,

With my data set, it’s ok for me to use .First or .Last since I will only have 1 duplicate at a time and I need perform calculations on these variables separately anyways. So I do two functions, 1st as described above, and 2nd one as below:

datatable.AsEnumerable().GroupBy(Function(a) a.Field(of double)("Code").ToString).Select(Function(b) b.Last()).CopyToDatatable()

Thanks!

Cheers @bcorrea

ok, no problem, it is just that when marked as solution other people would assume that code will solve their problem, when in truth it wont, although is a good start :wink:

1 Like

You are right @bcorrea :smiley:

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