Distinct rows from data table

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.

image

1 Like

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

@Sreeja26,

Please try below expression:

DataTableName.AsEnumerable.GroupBy(Function® New with {Key.Record = r(“File”)}).Select(Function (g) g.OrderByDescending(Function® r(“AGE”)).First()).CopyToDatatable()

1 Like
                   It is  Function (r)

With this query, I am getting the following:
image

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

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 :slight_smile:

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 :slight_smile:

2 Likes

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