How to get/select Duplicated Row in Excel Data Table

image

:mag: :mag: :mag: I want to select or get duplicated row

@Harpoon

If you just need to know which data is duplicate then please follow this

  1. Read the data from excel into dataTable dt
  2. 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

1 Like

To identify and select duplicated rows in an Excel DataTable using UiPath, you can follow these steps:

  1. Read the Excel file using the Read Range activity and store the data in a DataTable variable.

  2. 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.

  3. 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.

  4. Create a new DataTable to store the duplicated rows.

  5. 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.

1 Like

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