I want to check the duplicate row and delete base on conditions if they same value at A col, B col and any the value at D col = “OK”… then it will delete the first row and keep last row.
The output Table as below:
I have Linq code as below… how to add more the condition if any D Col = “OK”
(From row In Table.AsEnumerable()
Group row By k1= row(0).toString.Trim,k2= row(1).toString Into grp=Group
Let r = grp.last
Order By Array.IndexOf(Table.AsEnumerable.toArray,r)
Select r).CopyToDatatable()
Can you just correct me if I understand wrong…
You wanted to delete the row from Data table if
(Col A and Col B have same value) OR (Col D have OK) then we need to delete the row.
Please confirm.
And how to Sum “quantity” if the conditions are met? I have made the below code but i dont know how add the condition D Col = “OK” in my code… if any row in D Col = “OK” then it will Sum
(From d In dtSample.AsEnumerable
Group d By k1=d(“item”).toString.Trim, k2=d(“quantity”).toString.Trim Into grp=Group
Let s = grp.Sum(Function (x) Convert.ToDouble(x(“quantity”).toString.Trim))
Let ra = New Object(){k1, s, grp(0)(2), grp(0)(3)}
Select dtResult.Rows.Add(ra)).CopyToDataTable
As my datatable, i have two duplicate row ( Yellow Highlight ) have same value at “item” Col and “quantity” Col and one row has “OK” in D Col… then it will Sum the “quantity” Col and delete the first row ( keep last ).
I have tried to make this code but it not defined status = “OK” while checking duplicate row
(From d In Table.AsEnumerable
Group d By k=d(“item”).toString.Trim Into grp=Group
Let gf = grp.Where(Function (x) x(“status”).toString.ToUpper.Trim.Contains(“OK”)).DefaultIfEmpty(grp.First).toList
From g In gf
Group g By k1=g(“item”).toString.Trim Into grp2=Group
Let gf2 = grp2.First
Order By Table.Rows.IndexOf(gf2)
Select gf2).CopyToDataTable