How to sum of distinct values

Hi Team,

Below is the input sheet

image

and i want output as below

image

Assign activity
LHS: dtResult
RHS: YourDataTableVar.Clone()

Assign activity
LHS: dtResult
RHS:

(From d in YourDataTableVar.AsEnumerable
Group d by k=d("Employee").toString.Trim into grp=Group
Let s = grp.Sum(Function (g) CDbl(g("Amount").toString.Trim))
Let ra = new OBject(){k,s}
Select r = dtResult.Rows.Add(ra)).CopyToDataTable

Also have a look here:
[HowTo] LINQ (VB.Net) Learning Catalogue - Help / Something Else - UiPath Community Forum

DT.Asenumerable.Groupby(Function(r) r(0).Tostring).select(Function(r1) OutputDT.Rows.add(r1.key,r1.sum(Function(v) CDbl(v(0))).copytodatatable

Hi PPr,

I have tried ur solution but it is giving me the sum but in the employee column it should merge duplicates means it should find out the distinct values as below

see below is the input which i uploaded
image

the below is the output, here i dont want duplicates after summing the amount column it should keep the distinct value
image

i want output as below
image

LINQ Statement is doing this. We had done this in several projects. However let me crosscheck. Can you also share with us your implementation part?

Could it be the case, that you writing back the result into the same sheet?

It looks like we do see just the last 2 rows from origin data.
Kindly note: when dtnew has less rows count as dtold, reamining rows will rest in excel and not be cleared

Just check the current LINQ statement, when writing to a new worksheet

oh yeah, m sorry i forgot to change the sheet name, thank you so much for ur response

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