Hello all,
I need your help please.
I have a table that contains article numbers in column F, which can occur more than once. For the subsequent process I need the data formatted. This means that I only need the article number once and the complete total in column G. How can I map this?
(From d In DtBuild.AsEnumerable
Group d By k=d("Product Vendor Number").toString.Trim Into grp = Group
Let nj = grp.Sum(Function (x) CDbl(x("QTY_Request").toString.Trim))
Let ra = New Object(){k,grp.First()(1),grp.First()(2),nj}
Select r = DtOutput.Rows.Add(ra)).CopyToDataTable
Note : grp.First()(2) are the additional column values that need to be added
your suggestion is almost perfect, however the DT_Input has 1 columns, I need the same structure back in the DT_Output.
(From d In DT_Input.AsEnumerable
Group d By k=d(“Product_Vendor_Number”).toString.Trim Into grp = Group
Let nj = grp.Sum(Function (x) CDbl(x(“QTY_Requested_for_Return”).toString.Trim))
Let ra = New Object(){k,grp.First()(1),grp.First()(17),nj}
Select r = DtClone.Rows.Add(ra)).CopyToDataTable
I have adapted your hint but it still looks like this
(From d In DT_Input.AsEnumerable
Group d By k=d(“Product_Vendor_Number”).toString.Trim Into grp = Group
Let nj = grp.Sum(Function (x) CDbl(x(“QTY_Requested_for_Return”).toString.Trim))
Let ra = New Object(){k,grp.First()(1),grp.First()(17),nj}
Select r = DtClone.Rows.Add(ra)).CopyToDataTable
Try this expression and increment the column index based on the column count grp.First()(Index)
(From d In DT_Input.AsEnumerable
Group d By k=d(“Product_Vendor_Number”).toString.Trim Into grp = Group
Let nj = grp.Sum(Function (x) CDbl(x(“QTY_Requested_for_Return”).toString.Trim))
Let ra = New Object(){grp.First()(0),grp.First()(1),grp.First()(2),grp.First()(3),grp.First()(4),k,nj,grp.First()(7),grp.First()(8),grp.First()(9),grp.First()(10),grp.First()(11),grp.First()(12),grp.First()(13),grp.First()(14),grp.First()(15)}
Select r = DtClone.Rows.Add(ra)).CopyToDataTable