I want to select or get duplicated row
If you just need to know which data is duplicate then please follow this
- Read the data from excel into dataTable dt
- Use assign activity with
dt = dt.AsEnumerable.GroupBy(function(x) x("itemNo").ToString).Where(function(x) x.Count>1).Select(function(x) x.First).CopyToDataTable
Cheers
To identify and select duplicated rows in an Excel DataTable using UiPath, you can follow these steps:
-
Read the Excel file using the Read Range activity and store the data in a DataTable variable.
-
Use the Group By function to group the rows based on the desired criteria. For example, if you want to check for duplicate rows based on a specific column, you can group by that column.
-
Filter the groups to identify the duplicated rows. You can filter by checking if the count of rows in each group is greater than 1.
-
Create a new DataTable to store the duplicated rows.
-
Iterate through each group of duplicated rows, extract the rows, and add them to the new DataTable.
Hereβs an example workflow to achieve this:
Read Range:
- Input: Path to the Excel file
- Output: dataTable (DataTable variable)
Assign:
- To: groupedRows
- Value: dataTable.AsEnumerable().GroupBy(Function(row) row.Field(Of String)("ColumnName")).Where(Function(g) g.Count() > 1)
Assign:
- To: duplicatedDataTable
- Value: New DataTable()
For Each:
- TypeArgument: Group(Of DataRow)
- Values: groupedRows
If:
- Condition: item.Count() > 1
For Each:
- TypeArgument: DataRow
- Values: item
Add Data Row:
- Input: {row.ItemArray}
- DataTable: duplicatedDataTable
In the above example, replace "ColumnName"
with the actual column name you want to check for duplicates. The workflow groups the rows based on the specified column and filters the groups to identify duplicated rows. It then iterates through each group, extracts the duplicated rows, and adds them to the new DataTable named duplicatedDataTable
.
After executing this workflow, the duplicatedDataTable
will contain the duplicated rows from the original DataTable. You can further process or manipulate these duplicated rows as per your requirements.
Please note that the example provided assumes that the Excel file has been read into a DataTable using the Read Range activity. Make sure to adjust the activity names, column names, and variable names based on your specific workflow and data structure.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.