Linq Query on Group By and Sum

@tmond
Welcome to the forum

We can do it with folloing flow:
grafik

(From d In dtData.AsEnumerable
Group d By k=d("Col3").toString.Trim Into grp=Group
Let gs = grp.Sum(Function (x) CInt(x("Col2").toString))
Let raa = grp.Select(Function (g,i) If(i=0,g.ItemArray.Append(gs).toArray,g.ItemArray.Append(Nothing).toArray)).toarray
From m In raa
Select dtResult.Rows.Add(m)).CopyToDataTable

And will get:
grafik

Find starter help here:
GroupBy_1Col_AddSumToFirstMember.xaml (9.0 KB)

Also have a look here:

3 Likes