How to get the datarow with the lowest value from datatable


I’m looking for a way to get the datarow with the lowest value from a datatable. There are several methods to do a filtering on a datatable (Filter datatable, Select method, AsEnumerable with Function, LINQ). But I haven’t succeeded to do something similar with ‘Min’ or ‘Max’.

Let say I have a datatable ‘dt_F1’ with the columns ‘Name’ and ‘Points’ with the following rows:

Max | 100
Charles | 125
Fernando | 150
Louis | 90
Nick | 50
Pierre | 90

Assign activity:
Variabele DriverArray (type Array of datarows)

The expression dt_F1.AsEnumerable().Min(Function(row) CInt(row(“Points”))) will only get the lowest value. I want the row instead so I’m able to use the name later on for example.

About the screen cap: I know … ignore the for each for displaying the name :slight_smile:

Need your help! Thanks


Hi @richardvh, welcome to the Community.

You can try this expression:

DriverRow = dt_F1.AsEnumerable().OrderBy(Function(row) CInt(row("Points"))).First()

The First() method to retrieve the first row from the sorted DataTable, which will be the DataRow with the lowest value in the Points column. Finally, we assign the result to the variable DriverRow.

Edit: Output will be like-


Hope this helps,
Best Regards.

1 Like

Yes! It worked! Thanks Arjun

1 Like

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