Get distinct value in column excel

Hi all,

I have an excel files with a column which has
DEPARTMENT

Admin
Admin
Admin
BA
BA
BA
CA
CA
CA

And I would like to get the distinct value of the department column, how do i go around it?

Thanks.

hi @saraawq
For distinct column values you can use the below query
Datatable dt=dt.DefaultView.ToTable(true, “DEPARTMENT”) in assign activity

Thanks
Ashwin S

4 Likes

Hi @saraawq,

Refer this one for datatable filter

Distinct Based on the specific column name from the data table.

DataTable dt=dt.DefaultView.ToTable(true, "DEPARTMENT")
or
DataView view = new DataView(table)
DataTable distinctValues = view.ToTable(true, "Column1", "Column2" ...)
or
DataTable =DataTable.DefaultView.ToTable(true)

Regards,
Arivu

4 Likes

Hi @AshwinS2,

Thanks! But i got this error

Or it is because I’ve been using read range to get my data table?

@saraawq

Check Add headers property in Read Range Activity

Regards,
Mahesh

@saraawq I think you are passing different DataTable variable

it has the headers!

image

it is the same datatable variable :confused:

image

@saraawq
Once check in the excel that column name might have spaces at that start and ending.
Regards,
Mahesh

@saraawq can u attach workflow

@saraawq

And one more thing I think you are using the query inside Excel Application Scope… Please check the same by using outside of it.

Regards,
Mahesh

I got it to work, but how do i print out to know that it has the distinct values, cause when i message box, it doesn’t show any value.

I got it to work, but how do i print out to know that it has the distinct values, cause when i message box, it doesn’t show any value.
Thanks!

my variable is an object
image

image

my variable ‘dataDept’ is an object

@saraawq
Datadept should be datatable type.

Regards,
Mahesh

HI @saraawq,

use output data table activity to convert the data table to string and print it.

Regards,
Arivu

@saraawq
and if you want print your datatable in output panel or in message box. use Output DataTable Activity and use the string in message box

Regards
Mahesh