CGhoST
(John)
May 11, 2025, 7:29am
1
Hi Everyone
I have a Data table consisting of 2 columns and 5000+ rows.
I like to avoid using a for each loop as it will be time consuming so is there an efficient way of searching the WHOLE data table to see which row has the hightest int32 value and get the value from corresponding Column1
Thanks
@CGhoST ,
You can get the desired value like this.
Get Maximum value:
intMaxValue = dtInput.AsEnumerable().Max(Function(r) CInt(r.Field(Of Object)("Col2").ToString()))
Get Column 1 of the maximum value
strOutput = dtInput.AsEnumerable().Where(Function(r) r.Field(Of Integer)("Col2") = intMaxValue).Select(Function(r) r.Field(Of String)("Col1")).FirstOrDefault()
Output:
Sample Code:
MaxCountDemo.zip (33.9 KB)
CGhoST
(John)
May 11, 2025, 8:18am
3
Is it possible to do in just one assign activity?
@CGhoST ,
Yes, use this LINQ
dtInput.AsEnumerable().OrderByDescending(Function(r) r.Field(Of Object)("Col2").ToString()).Select(Function(r) r.Field(Of String)("Col1")).FirstOrDefault()
system
(system)
Closed
May 15, 2025, 9:38am
6
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.