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
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
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
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
→
Just check the entire data table on consistent format as described within the FirstAid
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.