Linq Query for Marking duplicates as duplicates but leave the last record as Non Duplicate

@shreyash_shirbhate

This was an interesting problem, check if the below works for you:

dt2 = dt.AsEnumerable()
    .GroupBy(row => new
    {
        ColumnA = row.Field<string>("ColumnA"),
        ColumnB = row.Field<string>("ColumnB")
    })
    .SelectMany(group =>
    {
        var lastIndex = group.Last();
        group.ToList().ForEach(row => row.SetField("IsDuplicate", row == lastIndex ? "No" : "Yes"));
        return group;
    })
    .CopyToDataTable();

Here’s how my the workflow looks like:

Arguments to Invoke Code activity:

2 Likes