How using LINQ I can filter my DataTable by max DateOrder and Number?
I have to leave all entries by Number with the maximum DateOrder.
must be output data:
we can do it with following LINQ
(From d In dtData.AsEnumerable Group d By k=d("Number").toString.Trim Into grp=Group Let md = grp.Max(Function (x) DateTime.ParseExact(x("DateOrder").toString.Trim,"dd.MM.yyyy",CultureInfo.InvariantCulture)) From g In grp Let gm = DateTime.ParseExact(g("DateOrder").toString.Trim,"dd.MM.yyyy",CultureInfo.InvariantCulture) Where gm.Date = md.Date Select g).CopyToDataTable
Ensure that System.Globalization is imported to the namespaces
If data comes from then excel keep in mind that after readin the data in the datatable could look different for the the date values. In that case just adopt the format string for the datetime string parsing
Find starter help here:
GroupBy_1Col_FilterMaxDate.xaml (7.8 KB)
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.