Distinct values in a datatable

Can anyone help me with code in uipath to get the distinct values in a datatable based on a particular column.

Detailed explanation of query:
I had a datatable which has around 8 columns and multiple rows i need to filter the datatable based on a date column with highest date then i need to get the distinct rows based on one column.

If any one suggests with some sample xaml code that would be great.



This will return a new datatable having only one column and distinct values of that column from the original table.

You can then iterate over this new datatable and in each iterationn use the datatable.select method for accessing only those rows where the distinct value matches.


I need the datarows that are filtered on a particular column

I will go with @akhi_s27’s solution but other way around.

first do a Datatable select

copyDataTable = dt.Select("Date= MAX(Date)").CopyToDataTable();

then get distinct values

copyDataTable .DefaultView.ToTable(True,"ColumnName")


First you need to install UiPath.Excel.Activities package.
search for remove duplicate activity
try it

1 Like

Hello Vaidya, for me I need the datarows but there are no additional filters to be applied. I have to select unique SSN from the SSN column and write all the datarows corresponding to them in a new sheet. Using your current solution I am unable to do so.
How could this be done? Would really appreciate your help.

dt.AsEnumerable().GroupBy(Function(a) a.Field(Of String)(“name”)).Select(Function(b) b.First).CopyToDataTable()

Try using this, you will get all the distinct column values along with data rows. Then you can apply filters as per your requirement.