Select first 25 UNIQUE rows in a datatable

@ppr you were very helpful on the first question I asked like this. I am now trying to choose the first 25 unique values from a datatable column. I think I need to use DefaultView…but not sure how.

depending on how the uniquness / duplicates are defiened (All columns or column set)

Just let us know the datatable structure and the uniqness definition. Based on this we can decide with which approach we want to start first.

step 1 use remove duplicate activity first

getting the first 25 rows Dt1=Dt1.AsEnumerable().Take(25).CopyToDataTable()

1 Like

The formula that I used to get the first25 vendors was as follows:
I used an assign with an Array of String (First25Vendors)
First25Vendors = CurrentDataTable.AsEnumerable.Take(25).Select(Function(x) x(“Vendor”).ToString.Trim).ToArray

That is working great except that it gives the first 25 regardless of if they are duplicates. I need to get the frist 25 unique vendors. No duplicates.

One of many options

First25Vendors = CurrentDataTable.AsEnumerable.Select(Function(x) x(“Vendor”).ToString.Trim).Distinct().Take(25).ToArray

@ppr that worked wonderfully! Thank you so much.

Karen

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