i have a excel file as follows: if the data in row a and row b is the same , then sum the row c data , for example the original excel file like
i want to get the result result like
anybody could help me ? thanks a lot !!!
i have a excel file as follows: if the data in row a and row b is the same , then sum the row c data , for example the original excel file like
Can you try this
dt = (From row In dt.AsEnumerable()
Group row By Name = row("Name").ToString().Trim(), Year = row("Year").ToString().Trim() Into Group
Select dt.Clone.Rows.Add(Name, Year, Group.Sum(Function(r) Convert.ToDouble(r("Salary"))))
).CopyToDataTable()
Regards,
use assign with below
dt = dt.AsEnumerable.GroupBy(function(x) x(0).ToString+x(1).ToString).Select(function(x) dt.LoadDataRow({x.First()(0).ToString,x.First()(1).ToString,x.Sum(function(y) cdbl(y(2).ToString)).ToString},false)).CopyToDatatable
cheers
If you want to group all column then try this
dt = (From row In dt.AsEnumerable()
Group row By Date1 = row("Date").ToString().Trim(),
Name = row("Name").ToString().Trim(),
Year = row("Year").ToString().Trim(),
Work = row("Work").ToString().Trim()
Into Group
Select dt.Clone.Rows.Add(Date1, Name, Year, Group.Sum(Function(r) Convert.ToDouble(r("Salary"))), Work)
).CopyToDataTable()
Regards,