Need help reorganizing datatable with Min and Max dates

Hello All,

I have a data table structure as seen below. This is booking data and each day is it’s own row in the datatable where the first row in each person group is the start date and time of the booking and the end date of the booking are on the last row in the group.

I need to transform it to the format below.

What would be the best way to do it. I’ve looked into dt.Select(), dt.AsEnumerable, but I haven’t had any look getting the desired end result.

Hi @dbaralt,

Have a look at this linq

(From d In TestDT.AsEnumerable
Group d By k=d("Occupant").toString.Trim Into grp=Group
Let ra = New Object(){k,grp.First()("Booking Start Date"),grp.First()("Booking Start Time"),grp.Last()("Booking End Date"),grp.Last()("Booking End Time")}
Select ResDT.Rows.Add(ra)).CopyToDataTable

Build a Datatable (ResDT) with all columns and Assign above linq to it

2 Likes

@dbaralt Have you already got the solution, If not can you send a sample excel file?

It worked! Thank you very much for your help.

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