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

Here is the table :point_down:

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

Any help ???

Hi @170290064

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)))

Hi @170290064

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

image

@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

image

Now how to add them into data table

@170290064
You can use the add data row activity
image

@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

image

@170290064

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

@lrtetala
@Brian_Mathew_Maben
@raja.arslankhan
@Quenton_Wayne_Rebello