Hi Guys, I am trying to merge the duplicate row value and add the value of other cell which is not same.
Column1
Column2
Column3
Column4
Column5
HOURS
PRICE
7039936
1225
BT
CF4N
1
0.10
7039936
1221
CU
CBRN
1
0.20
7039936
1221
CU
CBRN
1
3.44
7039936
1221
CU
CBRN
1
5.46
7039396
8621
MS
CGRN
1
7039396
8621
MS
CGRN
1
5.75
I am using the below code (which i got it other topic) which filter duplicate and join the particular cell value, however can someone tell me instead of joining cell, how to sum the cell value in the same code.
(From p In dt.AsEnumerable()
Group By x= New With { Key.a =p.Item(“Column0),Key.b=p.Item(“Column1),Key.c=p.Item(“Column2”),Key.d=p.Item(“Column3”),Key.e=p.Item(“Column4”)}
Into Grp = Group Select obj.LoadDataRow (New Object() {grp(0)(0), grp(0)(1), grp(0)(2), grp(0)(3), grp(0)(4),String.Join(””,grp.select(Function(c) c(“HOURS”), c(“PRICE”) ))},False)).CopyToDataTable
@antoromeo18 Do a group by and Use the Sum aggregate functions on the columns like Hours and Price. Group by Column1 and Column2 , SUM(Hours) and SUM(Price)
I also tried this code and got Input string not in correct format
(From p In dt.AsEnumerable()
Group By x= New With { Key.a =p.Item(“PO_NUMBER”),Key.b=p.Item(“JOB_NUMBER”),Key.c=p.Item(“DAMAGE”),Key.d=p.Item(“REPAIR_LINE_LOC”),Key.e=p.Item(“REPAIR_QUANTITY”)}
Into Grp = Group Select obj.LoadDataRow (New Object() {grp(0)(0), grp(0)(1), grp(0)(2), grp(0)(4), grp(0)(5), Convert.ToString(Grp.Sum(Function(c) Convert.ToDouble(c.Item(“PART_PRICE”).ToString)))},False)).CopyToDataTable
Yes… Firstly, you got the error you mentioned in the screenshot is because you have not specified the aggregation type you want properly. The aggregation type refers to the aggregation function, Sum, Avg, Min, Max etc.
So it should be in a two dimensional array format… which should come like {({"Hours", "Sum"}), ({"PRICE", "Sum"})}
The second error
is because when aggregating, you cannot have empty values in the aggregating columns. Those should be assigned with a zero or a default value.
I have done a sample workflow for you… Check it out. it works…