Summing Duplicates

Hi How can i sum up duplicates values based on reference and write in excel attached excel for expected outputTest.xlsx (10.0 KB)

can you just give some feedback on following:
data shows minus values
output shows absolute sums

is this intended or is the minus sign just ommited?

thanks for feedback

minus sign is omitted we just need to add in output - sign should not be there

You could use a for each of typeArgument as Object[] and this expression:

From dte In varDB.AsEnumerable Group dte By _
ID=dte(0), _
Values=dte(1), _
Into Group Select ({ _
ID, _ 
Values, _
Group.Sum(Function (x) (Convert.ToDecimal(x(2)))),
Names _

based on the EXCEL sample data and the info from your message find starter help here
shravya.xaml (12.7 KB)

  • first approach is LINQ based
  • second approach is preparing the aggregation / statics implementation within an interation over the groups and its member rows

Let us know your feedback

1 Like

the 1st linq approach is having invalid casting exception error that string type cannot be converted to double

the output is data table in for each how can we cast it to object

i was able to solve string to double issue but when selecting names column i do not want to join as the value is same for duplicates as well it the single value need to appear for names column without join how can i achieve that in that query?

with following line the first group member row name is fetched
Let n = grp.First()(“names”).toString

Its working Thanks

You just do like this:

1 Like

ok thank you

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