Filter a datatable and create a new datatable from selected column

I set the dt variable which has defaulted value new datatable.

Then I assigned it with below query:

dt_mydatatable.Select(“[ColumnA] = ‘filter’”).CopyToDataTable().AsDataView().ToTable(“Selected”, false, “ColumnB”).AsEnumerable().Distinct(DataRowComparer.Default).CopyToDataTable()

Basically it gives me rows with word ‘filter’ found in ColumnA and from there I create a new datatable. After that I copy the new datatable that only contains unique value from ColumnB.

Everything is working fine. Is there any better way to get the same result?
Im not good at scripting. I google the expression and combined them to get the result.

Thank you in advance for reading and replying :slight_smile:

Hi @mohamada
Fine

Welcome back to uipath community buddy

hope this should get you the same
dt_mydatatable.Select(“[ColumnA]= ‘filter’”).CopyToDataTable.DefaultView.ToTable(true,“ColumnB”)

Where defaultview is a method that helps us to get the distinct value of the specified column
here we have mentioned as true so we will be getting data with distinct value from the ColumnB as specified
Cheers @mohamada

3 Likes

Thanks mate. Its neat and working :slight_smile:

1 Like

Cheers @mohamada

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