I have a data table with 4 columns as follows
TransactionID, Date, Cost, Amount
749348828, 12-03-2022, 199, 500
474972940, 23-03-2022, 299, 299
749348828, 13-03-2022, 399, 500
How can I combine rows with same TransactionID and sum Cost and Amount for those two rows and add to 1st row
Result datatable should be
TransactionID, Date, Cost, Amount
749348828, 12-03-2022, 498, 1000
474972940, 23-03-2022, 299, 299
please help me with this ASAP
Thanks in advance
hey
welcome to our communty
please refer to this post, in this forum are so many question like this, please go through all of them
regards!
@Aluvala_Vamshi_Krishna you can do the pivot of the datatable to merge the duplicate row.
In regards to learn about pivot you can refer this
1 Like
Thank you so much for your quick response.
Is this the expected output?
If so, then you could give this code a try →
dt.AsEnumerable().GroupBy(Function(g) Tuple.Create(g("Name").ToString,g("Age").ToString)).Select(Function(s) Dt.Clone.LoadDataRow({s.Key.Item1,s.Key.Item2,s.Sum(Function(su) Convert.ToInt32(su("Amount").ToString.Trim))},False)).CopyToDataTable()
MergeandSum.xaml (7.0 KB)
Kind Regards,
Ashwin A.K
grouping.xaml (6.6 KB)
countbygroup.xlsx (9.4 KB)
edit column name as you want ,
thanks & regards
Veeraraj S