Find duplicate values in data table and do operation as per condition in the same table

Preparations:

Input:
grafik

Add Set:
grafik

(From d In dtData.AsEnumerable
Group d By k=d("TransID").toString.Trim Into grp=Group
Where grp.Count = 1
From g In grp
Group g By k2=g(0).toString.Trim Into grp2=Group
Let  til = String.Join(",",grp2.Select(Function (g2) g2(1)))
Let am = grp2.Sum(Function (g3) Convert.ToDouble(g3(2))).toString("F2")
Let ra = New Object(){grp2.First()(0), til, am}
Select r = dtAddSet.Rows.Add(ra)).CopyToDataTable

SplitSet
grafik

(From d In dtData.AsEnumerable
Group d By k=d("TransID").toString.Trim Into grp=Group
Where grp.Count > 1
Let  anl = String.Join(",",grp.Select(Function (g) g(0)))
Let ams = (Convert.ToDouble(grp.First()(2))/ grp.Count).toString("F2")
Let ra = New Object(){anl, k, ams}
Select r = dtSplitSet.Rows.Add(ra)).CopyToDataTable

With a merge Datatable Activity we can bring the AddSet and the SplitSet together in one datatable

We would recommend to do some more fine tuning, as this prototype was done as a quick show case