How to get Distinct values from a Column in DataTable

Hi All,

The distinct values of column - emp_id is saved in other excel file…

Regards,
Sonika

DataTable.Select(“emp id = ‘444’”)

Hi @Seem

You can try filter data table activity also -

https://activities.uipath.com/docs/filter-data-table

image

or

Thanks,
Prankur

Hi @PrankurJoshi
By using the -filter datatable activity - i can Keep the coulmns which ever i want. But this will take entire column… But in my case i want to select only part of the data at one time depending upon the .

@KarthikByggari
I have used the - DataTable.Select(emp_id=444) in the following way.

you can see in above screen in yellow color, I have passed the “row”

well then how to pass the coulmn name.

Regards,
Sonika.

Hi @Seem,

Default view used for getting the unique value from the table based on the column.

So first you are getting the unique value from the datatable using below code

Dt2=dt1.defaultview.totable(true,"column name")

Then using for each inside you are filtering the data using the below code

Dt1.select("columnname='"+row(0).ToString+"'")

Regards,
Arivu

1 Like

Hi @arivu96

or its related to 1st column?

Regards,
Sonika

Hey @Seem

I hope that was just kind of hint for you :slight_smile:

after getting distinct values in Datatable suppose Distinct_DT , Use For each and traverse it there use like your loop variable suppose item(“emp_id”).ToString() and use like

Datarow[ ] result = Dt1.select("[emp_id]='"+item("emp_id").ToString()+"'")

and use your results for your further usage if you want a datatable then

Datatable Result_dt = result.CopyToDatatable();

Let me know if you are still having any doubts or issues.

Regards…!!
Aksh

1 Like

Hi @aksh1yadav

I understood the code you have given above. Thank you.
But still row[0] - is not clear. its going through column 1’s all rows.

Regards,
Sonika

Nope

Regards…!!
Aksh

@aksh1yadav
@arivu96

How shall i take the array of rows to DT?

Can you please help me with this.

Regards,
Sonika

HI @Seem,

DT3=DT1.select("Inv.D='"+row(0).ToString+"'").CopyToDataTable()

Regards,
Arivu

1 Like

Hi @arivu96

Thanks in Advance
Sonika

Hey @Seem

Change your DT3 Variable Datatype from System.Data.Datatable[ ] to System.Data.Datatable.

Regards…!!
Aksh

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