Need help on LINQ to update the duplicate rows status in datatable

Hello All,

I have the below requirement and I would need your help on building the LINQ query

Requirement ::

  • If the columns “Name”, “Product Ordered”, “Ordered On” have same values for multiple rows, then I need to update the column “Status” as “Error” and “Error Description” as “Duplicate Row” for all the duplicate rows except for the first row

Input ::


Expected Output ::


Below is the sample input file
Orders.xlsx (11.1 KB)


Hi @sai_krishnaji_Gujjaru - Have a look on the below link

Hi @sai_krishnaji_Gujjaru ,

Could you Check the below Workflow : (11.1 KB)

Maybe Performing a GroupBy and then applying conditions on the grouped values to modify the necessary column would be a possible solution.
There maybe better methods for the given problem, But you could try out the workflow provided and let us know if you are able to get the desired output.

Linq used :

(From p In DT.AsEnumerable()
Group By x= New With {Key .Name = p("Name").ToString,Key .PrdOrd = p("Product Ordered").ToString,Key .OrdOn = p("Ordered On").ToString}
Into Grp = Group
Let updtedGrp =grp.Select(Function(g,i)AllColumnNames.Select(Function(c)If(i>0 AndAlso c.Equals("Status"),"Error",If(i>0 AndAlso c.Equals("Error Description"),"Duplicate Row",g(c)))).ToArray).ToArray
Select updtedGrp.Select(Function(y)OutputDT.Rows.Add(y))).SelectMany(Function(t)t).CopyToDatatable