Help me to create linq for following scenario case

In this excel if in column “Role in Company” value comes first time then in last new column “Role” write find and if it comes another time then duplicate
For eg in sheet2 of this excel
challenge.xlsx (16.6 KB)

@Swarit_Goyal

(From row In Dt.AsEnumerable()
                            Let role = If(Dt.AsEnumerable().Count(Function(r) r("Role in Company").ToString() = row("Role in Company").ToString()) > 1, "Duplicate", "Find")
                            Select Dt1.Clone().LoadDataRow(row.ItemArray.Concat({role}).ToArray(), False)).CopyToDataTable()

Hi,

Can you try the following sample?

 dt.AsEnumerable.GroupBy(Function(r) r("Role in Company").ToString).ToList().ForEach( Sub(g)
 g.First().Item("Role")="Find"
 g.Skip(1).ToList.ForEach(Sub(r)
     r.Item("Role")="Duplicate"
 End Sub
 )
End Sub
)

Sample20240208-3.zip (13.3 KB)

Regards,

Can you explain me or upload me the xaml

@Swarit_Goyal

Sequence.zip (2.2 KB)

1 Like

In this can u tell me why u made clone of DT1 and dt (we can add a data column in DT)

@Swarit_Goyal

In your Sheet 1 there is no Column name “Role”.So i created a new datatable with Dt means Sheet1 columns plus role column in my new datatable.

I hope you understand

If we add a data column like can we take Dt.Clone then

@Swarit_Goyal

Nope this will not work it will raise you a error

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