How to compare two rows of same datatable and if it's found match then merge it

Ex. compare both column center and function
Center Function Profit
ABCD 8234 132.30
AGCD 1334 632.45
TBUD 1234 -332.00
ABCD 8234 -332
ABCD 6234 -112.95

Answer Table Look’s like:
Center Function Profit
ABCD 8234 -200(Hint: 132.30-332=-199.70)
AGCD 1334 632.45
TBUD 1234 -332.00
ABCD 6234 -112.95

Assign activity
LHS: dtResult | DataType: DataTable
RHS: dtDataVar.Clone - dtData your origin DataTable

Assign Activity
LHS: dtResult
RHS

(From d in dtData.AsEnumerable
Group d by k1=d("Center").toString.Trim, k2=d("Function").toString.Trim into grp=Group
Let s = grp.Sum(Function (g) CInt(g("Profit").toString.Trim))
Let ra = new Object(){k1,k2,s}
Select r = dtResult.Rows.Add(ra)).CopyToDataTable
1 Like

Also have a look here:

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