When Name column values are duplicate then for col2 and col3's first row values should be copied in rest of the duplicate entries

Hi Team Can you help me with below problem -

When Name column values are duplicate then for col2 and col3’s first row values should be copied in rest of the duplicate entries.

Input DT
Name Col1 Col2 Col3
A A1 A2 A3
A A11 A22 A33
B B1 B2 B3
C C1 C2 C3
C C11 C22 C33
C C111 C222 C333
OutPut DT
Name Col1 Col2 Col3
A A1 A2 A3
A A1 A2 A3
B B1 B2 B3
C C1 C2 C3
C C11 C2 C3
C C111 C2 C3

Thanks!

Hi @Hitesh1 ,

Could you try with the below Expression :

OutputDT = (From r In DT.AsEnumerable
Group r By k=r("Name").toString.Trim Into grp=Group
From g In grp.DefaultIfEmpty
Select ra = {g("Name"),g("Col1")}.Concat(grp.First.ItemArray.Skip(2).ToArray).ToArray
Select OutputDT.Rows.Add(ra)).CopyToDataTable

Here, OutputDT is a datatable type variable which should be the Clone of DT the input Datatable, we could perform the clone using an Assign Activity as below :

OutputDT = DT.Clone
1 Like

@supermanPunch Thankyou so much for your response

Can you please help me to know how to implement this . I have kept this in a assign statement. And outpuDt is var but it is throwing exception copytodatatable not a member of datarow

Hi,

Can you share screenshot of error and/or whole the expression you input?

Regards,

It worked . Thankyou !

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