How to use Groupby sum of column values from Data table
Hi,
Can you try the following expression?
dt = dt.AsEnumerable.GroupBy(Function(r) r("PH").ToString).Select(Function(g) dt.Clone.LoadDataRow({g.Key,g.Sum(Function(r) Int32.Parse(r("Value").ToString))},False)).CopyToDataTable
Regards,
1 Like
Hi @Sreekar_Mulinti ,
Check the Below Linq Query :
(From d In dtData.AsEnumerable
Group d By k=d("PH").toString.Trim Into grp=Group
Let value = grp.Sum(Function (x) CDbl(x("Value").toString))
Let ra = New Object(){k, value}
Select dtData_New.Rows.Add(ra)).CopyToDataTable
Where dtData
is your Input Datatable and dtData_New
is the Clone of the dtData
1 Like
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.