How to find duplicate value in a particular column of a datatable

Hi,
I’ve a data table which contain multiple column but in “Account” column I’ve to check whether it contain any duplicate value or not, if it contain duplicate return as True otherwise False.

Thanks!

Assign activity
hasDuplicates | Boolean =

(From d in YourDataTableVar.AsEnumerable
Group d by k=d("ColName").toString.ToUpper.Trim into grp=Group
Where grp.Count > 1).Any()

Hi

Hope the below expression would help you

Use a assign activity

bool_output = If(dt.Rows.Count>dt.DefaultView.ToTable(True, “Account”).Rows.Count, True, False)

Here we are trying to have the actual datatable dt and datatable without duplicate records in column Account
And comparing the count
If the count is equal then no duplicate it give as false
If count is of actual datatable is greater than the one removed with duplicates then it has duplicate which means true

The value gets stored in boolean variable named bool_output

Cheers @subhamsinha055

Hi @subhamsinha055

if it contain duplicate return as True otherwise it will return as False

dt.AsEnumerable().
GroupBy(Function(row) row.Field(Of String)(“Account”)).
Any(Function(Group) Group.Count() > 1)

Hi,
You can try this

Assign

hasDuplicates = dataTable.AsEnumerable().GroupBy(Function(row) row(“Account”).ToString()).Any(Function(g) g.Count() > 1)

Try this-

  1. Assign activity:

    • Create a Boolean variable, e.g., isDuplicate.
    • Initialize it as False.
  2. For Each Row activity:

    • Iterate through each row in your DataTable.
  3. If activity:

    • Inside the For Each Row loop, add an If activity.
    • In the If condition, use an expression to check if the current row’s “Account” value exists in the rest of the DataTable.

    Expression: YourDataTable.AsEnumerable().Any(Function(row) row("Account").ToString = currentRow("Account").ToString)

    Here, YourDataTable should be replaced with the name of your DataTable variable, and currentRow is the variable representing the current row in the For Each Row loop.

  4. If the condition is True:

    • Set the isDuplicate variable to True.
    • Break out of the For Each Row loop since you’ve found a duplicate.
  5. After the For Each Row loop:

    • Add a message box, log message, or any other activity to display the value of the isDuplicate variable.
  6. Workflow is complete.

Thanks!!

Thank You @Nitya1 @Palaniyappan

1 Like

Thank you @ppr @mpraveen1902

Thank You @neha.upase

Perfect, so the topic can be closed?
Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum

yes that was solved.