First you will have to filter the data based on the fff column to consider only rows containing PA2 and then you can use the following code to get the sum of the duplicate columns. add this in the assign statement and add your datatable instead of dt
(From row In dt.AsEnumerable
Group row By key = New With { Key.group = row.Item(“aaa”).ToString.Trim
} Into grp = Group
Select dt.LoadDataRow(New Object() {
Key.group,
grp.Select(Function(x) x(“bbb”).ToString).First,
grp.Select(Function(x) x(“ccc”).ToString).First,
grp.Select(Function(x) x(“ddd”).ToString).First,
grp.Sum(Function (r) Convert.ToDouble(r.Item(“Amount”).ToString)),
grp.Select(Function(x) x(“fff”).ToString).First
}, True)).CopyToDataTable
after this you can merge the datatable containing PA4.
the first 3 lines of the code finds the unique values in the column “aaa” and then the next load datarow we need to add all the values that we need so for each of the unique values in “aaa”, grp.Select(Function(x) x(“bbb”).ToString).First finds the first value of in the datatable for that rows and grp.Sum(Function (r) Convert.ToDouble(r.Item(“Amount”).ToString)) sums the amount where all the rows contain the same value of the column “aaa”.
for example, the first 3 lines will give the group value as 1,3,10 and 6 and then for each of these values, for the column “bbb”,“ccc”,“ddd”,“fff” that it gets will be taken so for when “aaa” = 1, “bbb” = 1. When “aaa” = 3,“bbb”=2 and for amount it will sum all the rows for each value of the unique “aaa”.