How to Group by and filter using LINQ or Uipath activities

I want to do group by and filter. My requirement is i want to group by “Age” and get 1st occurrence but ignore if Age is “N.A.”.

Example Input :

Output :

Here as age is “N.A.”, I will ignore them from group by, but for age available is for a employee, then I take 1st occurrence if Age is same .

@Jena Use this linq

(From row In DT
Group row By a=row(“Name”).ToString.trim Into grp=Group
Select grp.last).CopyToDataTable

I want to group by “Age”, not name. If Age is “N.A.” then ignore in group by but those should be part of output excel.

@Jena

This image depicts a workflow for reading data from the "Input" sheet of "Excel1.xlsx", processing it, and then writing the processed data to the "InputRes" sheet within the same Excel workbook using UiPath activities. (Captioned by AI)

DT = (From row In DT.AsEnumerable()
Group row By key = row("Age").ToString() Into Group
From firstRow In If(key = "N.A", Group, Group.Take(1))
Select firstRow).CopyToDataTable()

Input:

A spreadsheet lists names, ages, and jobs of four individuals with some age entries marked as "N.A" and job roles including IT, QA Engineer, and RPA. (Captioned by AI)

Output:

The image shows a table of individuals with their names, ages, and job titles, where some age information is marked as "N.A". (Captioned by AI)

Regards,

Hi @lrtetala
can you pls elaborate the LINQ query, especially the 3rd row.
Thx

Hi @J0ska

Sure,

->Group row By key = row(“Age”).ToString() Into Group
This groups the rows by the value in the Age column

->From firstRow In If(key = “N.A”, Group, Group.Take(1))
If the key(Age) is “N.A”, it takes all rows in that group.
If the key(Age) is anything else, it takes only the first row of the group (Group.Take(1)).

Regards,

1 Like