DataTable get all unique values from a column

Hi, 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, thanks

1 Like

Filter based on one column -

yourDT.DefaultView.ToTable(true, "ColumnName")

Filter based on more than one column -

yourDT.DefaultView.ToTable(true, "ColumnName1", "ColumnName2"...."ColumnNameN")

Regards,
Karthik Byggari

9 Likes

did u get the solution for this?

Yes, it worked @vicky1234567890. Please find the workflow, use this as a function (Plug & Play).

GetDistinctDataTable.xaml (5.5 KB)

2 Likes

it’s working

1 Like

Hi Karthik, one correction I believe, it should be true instead of false.

1 Like

Thanks. You are right.

For distinct values - true.

Thank you for letting me know.

Hi one more question , If I need the datarows as well corresponding to the unique column values, how could that be done?

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

You can use this one as well.

I don’t know why it is not working in my case…can you help, please
I want unique Numbers in sheet2
If I’m doing wrong please correct me.
Thanks

check.zip (23.0 KB)