Sum the values of a column with similar rows in a data table as a single row into a new data table

hi please anyone help me explain this code if its going to help me achieve what I want
my = (From d In dt.AsEnumerable Group d By k1=d(“SenderName”).ToString.Trim.Replace(" “,String.Empty), k2=d(“BeneficiaryName”).toString.Trim.Replace(” “,String.Empty), k3=d(“BankName”).toString.Trim.Replace(” “,String.Empty), k4=d(“BeneficiaryAccountNumber”).toString.Trim.Replace(” “,String.Empty), k5=d(“SenderAccountNumber”).toString.Trim.Replace(” “,String.Empty) Into grp=Group Let s = grp.Sum(Function (x) CDbl(x(“TransactionAmount”).toString.Trim.Replace(” ",String.Empty))) Let ra = New Object(){k1,k2,K3,K4,K5,s,grp.First()(3)} Select my.Rows.Add(ra)).CopyToDataTable

Here is what i am trying to achieve:
Input dt:


output dt:

Hi, Thank You very much . what I posted actually works . Eevrything is okay now , I would have deleted this thread but I will leave it here because it might help someone in future :slight_smile: :smiley:

my = (From d In dt.AsEnumerable Group d By k1=d(“SenderName”).ToString.Trim.Replace(" “,String.Empty), k2=d(“BeneficiaryName”).toString.Trim.Replace(” “,String.Empty), k3=d(“BankName”).toString.Trim.Replace(” “,String.Empty), k4=d(“BeneficiaryAccountNumber”).toString.Trim.Replace(” “,String.Empty), k5=d(“SenderAccountNumber”).toString.Trim.Replace(” “,String.Empty) Into grp=Group Let s = grp.Sum(Function (x) CDbl(x(“TransactionAmount”).toString.Trim.Replace(” ",String.Empty))) Let ra = New Object(){k1,k2,K3,K4,K5,s,grp.First()(3)} Select my.Rows.Add(ra)).CopyToDataTable

mydt should have been initialized with the expected columns

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.