Grouping data table and select rows with Max date

Hello All,

I am trying to group one datatable and after grouping I have to find the row with max date(latest date) and that resultant row I want to put in a separate datatable.
Please find attached picture.
Here, input datatable having 5+ columns .I want to group data with column “Contract Number”. After grouping I want to find row which having latest or Max date .
That all latest dates rows I want to add in another datatable for further process.
(in picure first DT is an Inout dt and second (output dt is what i want in result ))
Can anyone please help in this.

Hi,

Hope the following sample helps you.

image

dt.AsEnumerable.GroupBy(Function(r) r("Contract Number").ToString).Select(Function(g) g.OrderBy(Function(r) DateTime.Parse(r("Invoice Date").ToString)).Last()).CopyToDataTable()

Sample20220506-1.zip (6.8 KB)

Regards,

1 Like

Thank you for your help!!!.. It resolved the issue.

1 Like

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