I have this datatable where I have to get the total sum of Time column and Cost column depending on its Project Code. I aim to use LINQ to be more efficient especially when processing thousands of rows.
Kindly see attached files for the desired output and excel file being used. Thank you.
In this case the group by approach can also be used
(
From row In dt_Data
Group row By k=row("Project Code").ToString.Trim
Into grp = Group
Select dt_Data.LoadDataRow({k, grp.Sum(Function(gr) CInt(gr("Time"))), grp.Sum(Function(gr) CInt(gr("Cost")))}, True)
).CopyToDataTable
(
From row In dt_Data
Group row By
k1=row("Skill Tribe").ToString.Trim,
k2 = row("Project Code").ToString.Trim
Into grp = Group
Select dt_Data.LoadDataRow({k1, k2, grp.Sum(Function(gr) CInt(gr("Time"))), grp.Sum(Function(gr) CInt(gr("Cost")))}, True)
).CopyToDataTable