I have a datatable with 3 columns How to find distinct values in one column of data table and output to be 3 column datatable as follows

I have a data table
example:
Code Value Amount
A001 1 10000
A001 1 20000
A002 1 10000
A003 1 10000
A002 1 20000
A003 1 20000
A004 1 20000
A005 1 20000

I need to get distinct values from code column and need to display the rest of two columns also in output as datatable
Code Value Amount
A001 1 10000
A002 1 10000
A003 1 10000
A004 1 20000
A005 1 20000

Hi @nikhil.s,

Distinct Based on the specific column name from the data table.

YourDataTable=YourDataTable.DefaultView.ToTable(true, “Code”)

Code --> your column name

Hope it will work☺️

T,
Guna

I used that method but it is giving output only one column i need values from 2nd and 3rd column also

Hey @nikhil.s

Please try the Below LINQ query.

YourDataTable = YourDataTable .AsEnumerable().GroupBy(Function(f) f.Field(Of String)(“Code”)).Select(Function(e) e.First).CopyToDataTable

T,
Guna

1 Like

@nikhil.s
find some starter help here introducing on retreiving, duplicates, nonduplicates or distrincts based on 1 key column:
FindDupsUniquesFirstFromGroup_By1Col.xaml (8.0 KB)

1 Like