Group By Sort with date col and get First Row off all Group.(Linq)

Hi Community,
I have a Datatable and I want to get first row of each group by sorting date column.(Latest should comes first)

Thanks

@Yoichi @ppr

Hi Guys,
Is it correct?

(From d In DT.AsEnumerable
Group d By d(“Col1”).ToString.Trim Into grp=Group
Select R=grp.OrderBy(Function (r)DateTime.Parse(r(“Date”).ToString)).First()).CopyToDataTable

We assume that the date vlaues are parseable with DateTime.Parse or others

(From d In DT.AsEnumerable
Group d By d("Col1").ToString.Trim Into grp=Group
Let gro = grp.OrderBy(Function (x)DateTime.Parse(x("Date").ToString.Trim).Ticks) 
Select r=gro.Last()).CopyToDataTable

check also if .Ticks can be omitted
Also, have a look at the OrderByDescending(…) method, but then we would use First()

Cross Reference:

@ppr
image
I tried your code but it gives this one.

ensure and retype every “ or ” to "

Check always the Quotations when copy paste Code snippets

@ppr
same in your case as well.

Not the same, Compilation error is gone, now the expected format is not matching the constraints of the used conversion method.

We already mentioned:

and on your other topic linked with the cross-reference, some additional feedback is shared

@ppr
After reading from excel I get this one

image

:ambulance: :sos: [FirstAid] Datatable: Debug & Analysis invalid DateTime Strings / String to DateTime Parsing Issues - News / Tutorials - UiPath Community Forum

Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

Just check the entire data table on consistent format as described within the FirstAid

@ppr


Problem Solved.Thanks

Perfect,
Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum

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