Sum duplicate values in Datable

Hello,

Apologies for another thread like that, however i can`t understand LINQ enough to adapt in my case. I have Datatable with two colummns. ID and VALUE. I just need to sum and remove duplicates.

Thank you from above

Hello @Add_Bddd

Does that mean in your datatable there are duplicate entries and you need to remove the duplicates and find the sum of values?

@Add_Bddd Do you want to add the the duplicate values of ID and Value columns and remove those duplicates. is that right ??

Hi @Add_Bddd ,

Maybe you require to perform a Group By and Sum Operation. Do take a Look at the Second Option in the Post Below :

You could also check on the other posts mentioned in it to get a learning on Linq.

Hello @ushu

That is correct. I have entries like:

ID VALUE
1 15
1 5
2 10

All i want is to have DT like
ID VALUE
1 20
2 10

@Add_Bddd

Check below LinQ query

(From d In YourDatatableVariable.AsEnumerable
Group d By k=d("ID").toString.trim Into grp=Group
Let ra = New Object(){k,grp.Sum(Function (x) Convert.ToDouble(x("VALUE").toString.Trim))}
Select NewDatatableVariable.Rows.Add(ra)).CopyToDataTable

Hope this may help you

Thanks

1 Like

Thank you very much @Srini84

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.