FilteredData.xlsx (7.5 KB)
This is my data table i want to extract the smallest and largest price from this excel for that i have used filtereddt.AsEnumerable().Min(Function(row) Cint(row(“Price”))) this linq function but shows the error "Assign: Conversion from string “” to type ‘Integer’ is not valid."Pls help to resolve this solution
Can you share some sample value values for price in the excel?
what sample value
so you basically have an excel file price as a column right? what are the values contained in price coumn.or if you could share the input excel it would be great
MergedData.xlsx (9.7 KB)
the above excel i have shared is the filtered one this is the main excel i want to extract the minimum and maximum from the filtered excel that i have mentoned above
Please remove , and $ from price ie. row(“Price”).Replace(“,”,“”).Replace(“$”,“”)
In the entire excel how can i remove that symbol
in that linq query itself you can use it filtereddt.AsEnumerable().Min(Function(row) Cint(row(“Price”).toString.Replace(“,”,“”).Replace(“$”,“”)))
it is still showing the same error
we cannot convert empy values / blank but can filter out
give a try at:
(From d in filtereddt.AsEnumerable()
Where Not (isNothing(d("Price")) OrElse String.IsNullOrEmpty(d("Price").toString.Trim))
Select x= Cint(row("Price").toString.Trim)).Min(Function (x) x)
Also we can decide for other strategies like:
- using the Int32.TryParse() method
- ordering the values and taking first / last for min and max
How can i assign this,can u elaborate
Assign Activity
LHS: myMin | DataType: int32
RHS:
(From d in filtereddt.AsEnumerable()
Where Not (isNothing(d("Price")) OrElse String.IsNullOrEmpty(d("Price").toString.Trim))
Select x= Cint(row("Price").toString.Trim)).Min(Function (x) x)
what is d i am not good at vb.net thats why i ask
it is like a local variable referencing the looped datarow within the LINQ
it looks fine when i remove the null values but i have to filter that price and write it into new excel sheet i filter using filter datatable but shows no values how it can be rectified
Can you show the filter condition?
do u got it
Try
Convert.ToDecimal(cheapest).ToString(“#,##0”) to convert it to original format and then do the filter operation. I think you need to add $ as well in the beginning
in the filterdata table?