Linq query to get a particular values from column A that has only a specific values in column B but not anything else

Hello Team,

I have a datatable as below.

Name Activity
Ram Sport
Ram Warrior
Lakshman Warrior
Sita Warrior
Sita Sport
Hanuma warrior
Bharata sport
Kshatragna Sport

I am expecting a linq query which give me an output datatable that contains names who is only having warrior as value but not other values.

The expected output is :
image

Thanks!

@Jeevan_Reddy

try this in assign

requiredtd = dt.AsEnumerable.GroupBy(function(x) x("Name").ToString).Where(function(x) x.Count=1 AndAlso x(0)("Activity").ToString.ToLower.Equals("warrior")).Select(function(x) x.First).CopyToDatatable

cheers

Hi @Jeevan_Reddy

Try this

(From row In dt.AsEnumerable()
                              Group row By Name = row.Field(Of String)("Name") Into Group
                              Where Group.All(Function(r) String.Equals(r.Field(Of String)("Activity"), "Warrior", StringComparison.OrdinalIgnoreCase))
                              Select Group.First()).CopyToDataTable()

Regards,

1 Like

@Jeevan_Reddy

(From row In DT.AsEnumerable()
                              Group row By Name = row.Field(Of String)("Name") Into Group
                              Where Group.All(Function(r) String.Equals(r.Field(Of String)("Activity"), "Warrior", StringComparison.OrdinalIgnoreCase))
                              Select Group.First()).CopyToDataTable()

Input:

image

Output:

image

Regards,

Hi @Jeevan_Reddy,

Since UiPath offers this feature, I’m not sure if you’re already aware. However, the Expression Editor can generate this type of content for you (see screenshot).

Also, please check out this link.

UiPath Community 2023.12 Release - News / Release Notes - UiPath Community Forum

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