Data-table issue - select max value and choose different column value

Hi Guys,

My question is to filter “AAA” in the Type column, select the min “level” value and get max rev value (7).

I am not familiar with VB code. I am wondering how can I just use one or two sentences to filter the right value for the below table?

Thank you

Type Level Rev
AAA 2 6
BBB 1 4
CCC 1 4
DDD 1 4
AAA 3 5
AAA 4 4
BBB 2 3
DDD 2 7
CCC 2 3
AAA 1 7


Can you try the following expression?

dt.AsEnumerable.Where(Function(r) r("Type").ToString="AAA").OrderBy(Function(r) r("Level")).ThenByDescending(Function(r) r("Rev").ToString).First().Item("Rev").ToString()


1 Like

Check this below linq code to get maximum and minimum value, @Chen_Kenny
Maximum value = TestDt.AsEnumerable.Where(Function(x) x(“Type”).ToString.Trim.Equals(“AAA”)).CopyToDataTable().AsEnumerable.Max(Function(m) Cint(m(“Rev”).ToString.Trim))

Minimum value = TestDt.AsEnumerable.Where(Function(x) x(“Type”).ToString.Trim.Equals(“AAA”)).CopyToDataTable().AsEnumerable.Min(Function(m) Cint(m(“Rev”).ToString.Trim))
Hope this may help you :slight_smile:


Thank you, guys. Your solutions work for me!