Let us know the Full details. With which data is the loop happening ? Are we looping through the Datatable that you have specified ? But it only has one row ?
We do understand that an Update needs to happen to the Datatable, But we do not know if that is the Datatable that is being looped or do we have some other Collection that we are comparing with ?
It’s not in loop i am add the value in datatable inside for loop in first loop the value of I’d type value will be added when the loop run second time if the ID and type is same as previous added in datatable need to append as i mentioned above
For cases like these, maybe an approach using Merge Datatables Activity, Combining the Two Datatables into one at first and then performing the Grouping based on ID and Type Columns and Summing up the Value Column could be a Solution.
(From r In DT.AsEnumerable
Group By k = r("ID").ToString, a =r("Type").ToString Into grp = Group
Let ra =New Object(){k,a,grp.Sum(Function(x)CDbl(x("Value").ToString))}
Select OutputDT.Rows.Add(ra)).CopyToDatatable
Debug Panel :
Inputs (DT & DT2) :
Merged DT :
Output DT :
Let us know if this method works out for your case.
Is Date the only other column or do you have many other columns which you would need to concatenate ?
You could change the Linq query to the below for the case where Date column values are to be concatenated :
(From r In DT.AsEnumerable
Group By k = r("ID").ToString, a =r("Type").ToString Into grp = Group
Let ra =New Object(){k,a,grp.Sum(Function(x)CDbl(x("Value").ToString)),String.Join(",",grp.Select(Function(x)x("Date").ToString).ToArray)}
Select OutputDT.Rows.Add(ra)).CopyToDatatable
There was no mention of the name column or that it must not be concatenated. Do provide us with a complete requirement as to what/How many columns are present. What columns are needed to be combined, concatenated and what columns are to be left alone/Keep First instance.
Do note that providing the names of the columns would be helpful for us to configure the GroupBy clause in an approachable manner.
We do not want to go back and forth on multiple sub requirements on a Same Topic, which would make the Topic requirement unclear for others when searched.
(From r In DT.AsEnumerable
Group By k = r("ID").ToString, a =r("Type").ToString Into grp = Group
Let ra =New Object(){k,a,grp.Sum(Function(x)CDbl(x("Value").ToString)),String.Join(",",grp.Select(Function(x)x("Date").ToString).ToArray),grp(0)("Name").ToString}
Select OutputDT.Rows.Add(ra)).CopyToDatatable