In below image, I am taking out the duplicates base on the column A and Column B. So my row 2,3 and 7 are duplicate, So I want to mark 2 and 3 as duplicate and will leave the last occurring duplicate entry as non duplicate.
If not clear, then let’s see second example so, 4th and 9th rows are duplicate so I will mark only 4th row as duplicate and will leave the last occurring entry as non duplicate. So that I can process those records.
(Note: if there are duplicates then I want the last occurring entry mark as non duplicate. Also, Lets say if there is no duplicates and only one row entry then that entry will remain as non duplicate. Which you can check in 3rd row.)
Thanks for the reply. You did not get any compilation error for Invoke code? Because I am getting below one. I used the same expression which you have provided.
(From d In dt
Group d By k=d("Column A").toString.Trim,l=d("Column B").toString.Trim Into grp=Group
From g In grp.AsEnumerable
Let gra= If(grp.Count>1 AndAlso CType(g,DataRow).Equals(CType(grp.Last,DataRow)),g.ItemArray.Take(g.ItemArray.Count-1).Append("Yes").ToArray,g.ItemArray.Take(g.ItemArray.Count-1).Append("No").ToArray)
Select dt.Clone.Rows.Add(gra)
).CopyToDatatable
From Debug Panel :
Let us know if the ordering also matters, as we do see a change in the original data order.
When we can rely on the structure then we could do it with LINQ and DataTable reconstruction approach by
Assign Activity
dtResult = dtOrig.Clone
Assign Activity
dtResult =
(From d in dtOrig.AsEnumerable()
Group d by k1= d("ColumnsA").toString.Trim, k2= d("ColumnsB").toString.Trim into grp=Group
From i in Enumerable.Range(0,grp.Count)
Let g = grp(i)
Let isd = If(i = grp.Count -1, "No","Yes")
Let ra = g.ItemArray.Take(2).Append(isd).toArray
Select r = dtResult.Rows.Add(ra)).CopyToDataTable