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
Values from a column in UiPath - Need most efficient way
11.3k Views Asked by Sergio Salerno At
2
There are 2 best solutions below
0

I found this post:
Add DataColumn by using Add DataColumn activity
Extract the Duplicate rows and store in a datatable
dt1
Get the distinct values by using:
dt2 = dt1.DefaultView.ToTable(True)
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
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.
I think what you want to do is to implement a UiPath filter based on a single column with something like this:
You can scale this to do multiple column filters as well by simply adding extra column names:
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.