I have extracted below excel data to datatable and want to filter as follow:
I want to get distinct records based on Max age.
Pls help me with this.

I have extracted below excel data to datatable and want to filter as follow:
I want to get distinct records based on Max age.
Pls help me with this.

try this
dataTable.DefaultView.ToTable(true, “ColumnName”)
I want to get all distinct records based on file name and max age.
With that query I will get only one column with distinct ages
Please try below expression:
DataTableName.AsEnumerable.GroupBy(Function(r) New with {Key.Record = r(“File”)}).Select(Function (g) g.OrderByDescending(Function(r) r(“AGE”)).First()).CopyToDatatable()
It is Function (r)
With this query, I am getting the following:

I would like to get below (without red coloured cells)

Can someone help me
Hi @Sreeja26,
Try below code
((From LineNo In dt.DefaultView.ToTable(True,"ID").Select().ToList() Select (From row In dt.Select Orderby row("AGE") descending Where row("ID").ToString=LineNo("ID").ToString Select row).ToList(0)).ToList()).CopyToDatatable()
Regards,
Arivu ![]()
Thank you @arivu96
But I am getting following error. Pls let me know if i am missing anything:
The query is correct only but make it Orderby is Order by.
i missed the space
((From LineNo In dt.DefaultView.ToTable(True,"ID").Select().ToList() Select (From row In dt.Select Order by row("AGE") descending Where row("ID").ToString=LineNo("ID").ToString Select row).ToList(0)).ToList()).CopyToDatatable()
Flowchart.xaml (13.0 KB)
Regards,
Arivu ![]()
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.