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
Filter based on one column -
Filter based on more than one column -
yourDT.DefaultView.ToTable(true, "ColumnName1", "ColumnName2"...."ColumnNameN")
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)
Hi Karthik, one correction I believe, it should be true instead of false.
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.
check.zip (23.0 KB)
If i dont have column headers then how to provide column number
Hi @Doonline ,
Try this -
(From row In dt_TransactionData
Group row By a=row(0).toString.Trim Into grp=Group
here instead of 0 pass your column index.
Try this below expression
(From p in DT.Select() where( From q in DT.Select() where q(“NLC”).Equals(p(“NLC”)) Select q).ToArray.Count=1 Select p).ToArray.CopyToDataTable()
Hope it will help you.
In this i am get hole column but I Want only the specified name in that column can you help me
Hey @KANTHAIAH_SAYALA are you referring to a specific Row in the Column? If so, I would suggest using the Filter Datatable Activity.