How to check for duplicate values and add in status column if any

I need to check for repeated values and write in the status column “Duplicate”

Ex:
image

Hi @Enzo_Antonio

To check if a column in Excel has duplicate values and update the status column to “Duplicate” using UiPath and LINQ queries, you can follow these steps:

  1. Excel Application Scope (provide the path to your Excel file)
  2. Read Range (output: dtData, specify the range that includes the column you want to check)
  3. Assign (left side: groupedData, right side: dtData.AsEnumerable().GroupBy(Function(row) row.Field(Of String)(“ColumnName”)).ToDictionary(Function(group) group.Key, Function(group) group.ToList()))
  4. For Each row In dtData.AsEnumerable()
  5. Assign (left side: currentValue, right side: row.Field(Of String)(“ColumnName”))
  6. Assign (left side: groupList, right side: groupedData(currentValue))
  7. If (groupList.Count > 1)
  8. Assign (left side: row(“Status”), right side: “Duplicate”)
  9. End If
  10. End For Each
  11. Write Range (input: dtData, specify the range to write back to)
  12. End Excel Application Scope

Make sure to replace "ColumnName" with the actual name of the column you want to check for duplicates.

Hope it helps!!

Hi @Enzo_Antonio
Read range
For each
Assign activity
A=“”
Assign activity
Name1=current row(“Name”)
If A=Name1
Then write cell
Else
A=Name1

Hope it helps!!

@Enzo_Antonio ,
You can refer below workflow

Main.zip (2.5 KB)

Sample Output :
image

Regards,

1 Like

what type should the variable “goupedData” be?

List of string datatype @Enzo_Antonio

dt.AsEnumerable.GroupBy(Function(val) val(“Name”)).Where(Function(val) val(“Name”).ToString.count >1).Select(Function(val) val.(“Name”).Last).ToArray

This will give an array of values that have more than one value. Search for these values in the datatable and mark as duplicates

Hi @Enzo_Antonio

Try this:
dt.AsEnumerable().GroupBy(Function(x) x("Name").ToString).Where(Function(g) g.Count() > 1).SelectMany(Function(g) g).ToList().ForEach(Sub(row) row("Status") = "Duplicate")

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