# Arcade expression to find min() not zero

420
3
02-28-2020 01:03 PM
New Contributor III
Hi!  I am trying to get familiar with the new Arcade language.  Specifically as used in Attribute Rules.

I am trying to create an Arcade expression to calculate a field in ArcGIS Pro. In my streets feature there are 4 number fields to evaluate. I can easily use the Min() function to do this. The problem that I am having is sometimes there is a 0 in one or more fields. I need the lowest number that is not a 0. In python I had this script which worked well:

``min([x for x in ( !L_F_ADD!, !L_T_ADD!, !R_F_ADD!, !R_T_ADD!) if x is not 0])``

I have tried redoing this in Arcade but can't figure it out. Any ideas?

1 Solution

Accepted Solutions
Esri Esteemed Contributor

Hi spsummers ,

You are probably not going to like it, but those powerful python list comprehensions are not available in arcade. Can you try this?

``````var minv = 99999;
for (var i in arr) {
var v = arr[i];
if (v!=0 && !IsEmpty(v)) {
if (v < minv) {
minv = v;
}
}
}

if (minv == 99999) {
return null;
} else {
return minv;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍``````
3 Replies
Esri Esteemed Contributor

Hi spsummers ,

You are probably not going to like it, but those powerful python list comprehensions are not available in arcade. Can you try this?

``````var minv = 99999;
for (var i in arr) {
var v = arr[i];
if (v!=0 && !IsEmpty(v)) {
if (v < minv) {
minv = v;
}
}
}

if (minv == 99999) {
return null;
} else {
return minv;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍``````
New Contributor III

Thank you! Your code worked.  I also asked this question on another forum (Geographic Information Systems Stack Exchange )  The solution presented by Hornbydd is this:

```var inArray = [\$feature.FromAddr_L,\$feature.ToAddr_L,\$feature.FromAddr_R,\$feature.ToAddr_R];
var sortedArray;
sortedArray = sort(inArray);
for(var i in sortedArray)
{
if (sortedArray > 0) break;
}
return sortedArray;```
``````

Both solutions work in the Field Calculator.  It will be interesting to see if they work in the Attribute Rules.

Thank you!

Esri Esteemed Contributor

Hi spsummers ,

That is correct, I thought about this too, but I didn't know if you had any negative values to consider. Thanks for sharing.