# How to find max and min price in the table with linQ method?

Here is the table

Each prices has currency next to price (“TL”). First i have to trim it i guess

Any help ???

For MAX:

dtTable.AsEnumerable().Max(Function(row) CDbl(row(“Price”)))

For MIN:

dtTable.AsEnumerable().Min(Function(row) CDbl(row(“Price”)))

I hope it helps!!

@170290064 by linq query you can trim it inside

``````dtTable.AsEnumerable().Max(Function(row) CDbl(split(row(“Price”).ToString, " ")(0)))

``````

For min

``````dtTable.AsEnumerable().Min(Function(row) CDbl(split(row(“Price”).ToString, " ")(0)))
``````

Check the below linq methods

For maximum value in the column.
Dim maxPrice As Double = CType(inputDataTable.AsEnumerable().Max(Function(row) Double.Parse(row(“Price”).ToString())), Double)

For Minimum value in the column
Dim minPrice As Double = CType(inputDataTable.AsEnumerable().Min(Function(row) Double.Parse(row(“Price”).ToString())), Double)

Hope it helps!!

@170290064 try above one and let me know.

Hi,

How about the following?

MAX

``````dt.AsEnumerable.Max(Function(r) Double.Parse(System.Text.RegularExpressions.Regex.Match(r("Fiyat").ToString,"[\d.,]+").Value,System.Globalization.NumberStyles.Any,New System.Globalization.CultureInfo("tr-TR")))
``````

MIN

``````dt.AsEnumerable.Min(Function(r) Double.Parse(System.Text.RegularExpressions.Regex.Match(r("Fiyat").ToString,"[\d.,]+").Value,System.Globalization.NumberStyles.Any,New System.Globalization.CultureInfo("tr-TR")))
``````

Regards,

@170290064

Assign activity:
To: prices
Value: dt.AsEnumerable().Select(Function(row) CDbl(row(“Price”).ToString().Replace(“TL”, “”))).ToList()

Assign activity:
To: maxPrice
Value: prices.Max()

Assign activity:
To: minPrice
Value: prices.Min()

i chose double type but get this error why

@170290064 becaue your values contains two dots

lemme try another one

@170290064

Try assign max(string)=dt.AsEnumerable.Max(Function(x) x(“Fiyat”).ToString.split(" “c)(0))
assign mix(string)=dt.AsEnumerable.Mix(Function(x) x(“Fiyat”).ToString.split(” "c)(0))

Then update it into your datatable.

@170290064 Try rewriting the quotes in the LINQ expression

Now how to add them into data table

@170290064
You can use the add data row activity

@170290064 use add datarow and
Give datatable which you build
And pass values like this
{Max,min}
In array section

dt(“MinPrice”) = linq Exp for min price
dt(“MaxPrice”) = linq Exp for max price

@170290064

``````dtTable.AsEnumerable().Max(Function(row) CDbl(split(row(“Price”).ToString, " ")(0).Replace(".",""))
``````