LinQ query help regarding duplicates

Hi @Biswas_Ishan

Try this:

(From row In AdditionsReportDT.AsEnumerable()
Group row By associateID = row.Field(Of String)("Associate ID") Into Group = Group
Let maxDateRow = If(Group.Count() = 1,
                    Group.First(),
                    Group.OrderByDescending(Function(r As DataRow) DateTime.ParseExact(r.Field(Of String)("Effective Date"), {"MM-dd-yyyy", "M/dd/yyyy"}, System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.None)).First())
Select maxDateRow).CopyToDataTable()

This should work
Regards

1 Like