Values from a column in UiPath - Need most efficient way

11.3k Views Asked by At

In UiPath, what’s the most efficient method to get a list or array of all the unique values in a column from a DataTable? Preferably without looping

2

There are 2 best solutions below

0
On BEST ANSWER

I think what you want to do is to implement a UiPath filter based on a single column with something like this:

yourDT.DefaultView.ToTable(true, "ColumnName")

You can scale this to do multiple column filters as well by simply adding extra column names:

yourDT.DefaultView.ToTable(true, "ColumnName1", "ColumnName2"...."ColumnNameN")

Efficiency vs simplicity

By the way, the discussion of what's 'most efficient' is debatable. I'd say these are the simplest approaches. I'm sure there's some genius out there who could write their own code to shave some clock cycles off the default implementation. But for combined efficiency and simplicity, this is the way to go.

0
On

I found this post:

  1. Add DataColumn by using Add DataColumn activity

  2. Extract the Duplicate rows and store in a datatable dt1

  3. Get the distinct values by using:

    dt2 = dt1.DefaultView.ToTable(True)
    
  4. Run for each row for datatable dt in if condition

    (From p in dt2.Select()
    where string.Join(",",p.ItemArray).Equals(string.join(",",row.ItemArray)
    Select p).ToList.Count>0
    
  5. Then Assign row("Flag")="flag"

This flags the rows. So you can easily adapt it. Main part is the DefaultView.ToTable.


Another idea is simply using an existing library like this.