Searching/detecting values > 0 in a data table - Boolean condition

I want to verify all cells in a data table are values > 0.
Another way of approaching it is to be able to search the data table for “0.0”. I don’t care where the value is or how many times it occurs. I just need to know if it’s there or not.

I’m using an If activity nested within a For Each Row in Data Table activity.

The data table was scraped from a web page in text format because it was a mixture of both text and numeric data and I need both. I used the filter data table activity to isolate the numeric data but a lot of conditions I tried to use were springing errors I think because the numbers are formatted as text.
The following began to work successfully: currentrow.itemarray.all(function(a) cint(a.tostring)>0)

However for values in the data table > 0 and < 1 the condition is registering them as “0”
So values like 0.5 are branching the activity to ‘Else’.

I tried changing it to the following but it made no difference:
currentrow.itemarray.all(function(a) cint(a.tostring)>0.0)

I’ve also tried using the following condition, but it was not detecting the 0.0 values when I tested data table with zeroes:
CurrentRow.ToString.Contains(“0.0”)

Could anyone suggest an alternative boolean expression?

Thank you!

Hi @ljones

Try the below condition in If:

currentrow.ItemArray.Any(Function(a) If(a.ToString() = "0.0", True, False))

Hope it helps!!
Regards

@ljones

dataTable.AsEnumerable().All(Function(row) row.ItemArray.All(Function(cell) Convert.ToDouble(cell) > 0))

dataTable.AsEnumerable().Any(Function(row) row.ItemArray.Any(Function(cell) cell.ToString() = “0.0”))

Hi,

How about the following expression?

CurrentRow.ItemArray.All(Function(o) Double.TryParse(o.ToString,New Double) AndAlso Math.Floor(Double.Parse(o.ToString))>0)

OR if you need to evaluate whole the datatable, the following may be better.

dt.AsEnumerable.All(Function(r) r.ItemArray.All(Function(o) Double.TryParse(o.ToString,New Double) AndAlso Math.Floor(Double.Parse(o.ToString))>0))

Regards,

This worked perfectly. Thank you!

1 Like

You’re welcome @ljones

Happy Automation.

Regards

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