How to deal excel problem, if row a and row b is same ,the sum the row c number ?

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 !!!

Hi @chrisjiyiwei

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,

@chrisjiyiwei

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 the excel like this


how to get the result file

@chrisjiyiwei

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,