How to compare columns in LINQ methods in UiPath
Introduction :
Filtering columns in LINQ within UiPath is a powerful way to handle and manipulate data tables effectively. LINQ (Language Integrated Query) allows you to perform queries on collections of data, such as DataTables, in a more readable and concise manner.
Here’s a step-by-step guide on how to filter columns in LINQ in UiPath Input file:
Step1 : Use read range activity for reading input file .
The input files contain patient reports for both males and females. Here, we need to filter only the male reports from the DataTable
· For Each Row in Data Table:
- Purpose: This activity iterates through each row of the data table (DT).
- Configuration:
- Data Table: The input data table (DT) is specified here.
- Item Name: The current row being processed is referenced as CurrentRow.
· Assign Activity:
- Purpose: To filter the data table based on a specified condition.
- Configuration:
- Save to: A variable (Filterdt) is used to store the filtered data table.
- Value to Save: The expression “DT.AsEnumerable.Where(function (row) row(“gender”).ToString.Contains(“Male”)).CopyToDataTable” is used to filter the rows. This LINQ query applies the filtering logic to the data table. The specific condition inside the Where clause determines which rows are included in the filtered data table.
· Write Range Workbook:
- Purpose: To write the filtered data back to an Excel file.
- Configuration:
- Workbook Path: The path to the Excel file where the filtered data will be written (“Input.xlsx”).
- Sheet Name: The name of the sheet where the data will be written (“sheet1”).
- Data: The filtered data table (Filterdt) that will be written to the specified Excel sheet.
How to Use This Workflow
To use this workflow effectively, follow these steps:
- Prepare Your Data Table: Ensure that your data table (DT) is properly loaded with the data you want to filter. This data table should be populated before the For Each Row in Data Table activity.
- Define Your Filtering Criteria: Modify the LINQ query inside the Assign activity to define your filtering criteria. This criteria should reflect the specific rows you want to include in the filtered data table.
- Set the Output File Path: Make sure that the path specified in the Write Range Workbook activity (“Input.xlsx”) points to a valid location where you have write permissions.
- Run the Workflow: Execute the workflow to process the data. The workflow will iterate through each row, apply the filtering logic, and write the filtered data to the specified Excel file.
Output :
Conclusion
This UiPath workflow provides a straightforward way to automate the process of filtering data from an Excel file and saving the results back to the file system. By understanding each component and how it contributes to the overall process, you can customize this workflow to suit your specific data processing needs. Whether you are dealing with large datasets or need to automate repetitive tasks, this approach can save time and improve efficiency.
Also Read – Extract Data From Structured Data in UiPath