Identify the Duplicates and sum the value

@Sob
Good News I got it fully running :slight_smile:
Here is the sample Workflow
LINQ_2KeyGroupIn.xaml (8.6 KB)

Here a short explanation how it is implemented

Read Range Source Excel File - getting a datatable

Assign - returning the informations on the so called duplicates:
returns a List of String()
Statement:
(From r In dtSample.AsEnumerable()
Select C1 = r(0).ToString.Trim, C2 = r(2).ToString.Trim
Group By C1, C2 Into Group
Select C1, C2, Count = Group.Count
Where Count > 1
Select New String() {C1,C2}).ToList

Assign - returning the result as per requirement:

I need to find duplicate for ID and key column.if duplicates ID contains duplicate key.Then i need to sum Value1 ,Value 2 and value 3.

Requirements for Column Name was unclear so i return the value from first row of duplicate (xxx) similar to your origin requirement

Statement:
(From d In Duplicates
Let rows = dtSample.AsEnumerable.Where(Function ( r ) r(0).ToString.trim.equals(d(0)) And r(2).ToString.trim.equals(d(1)))
Select New Object() {
rows(0)(0).ToString,
rows(0)(1).ToString,
rows(0)(2).ToString,
rows.Sum(Function ( r ) CInt(r(3))),
rows.Sum(Function ( r ) CInt(r(4))),
rows.Sum(Function ( r ) CInt(r(5))),
rows.Sum(Function ( r ) CInt(r(6)))
}).ToArray

Returns an Array of Object()

Assign - preparing a second database (dtResult) by using the same table structure from origin
Statement: YourDataTableVar.Clone

For each / add DataRow
Iterating over the Array of Object() - the calculated rows and adding this to dtResult

5 Likes