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?


You are using a coding method called list comprehension which is something that the language Python understands. To the best of my knowledge this technique does not exist in Arcade so you need to approach the problem in a different manner.

Below is some code I worked up and it returns the first non-zero value from a sorted array.

f1 to f4 would be your fields.

var inArray = [$feature.f1,$feature.f2,$feature.f3,$feature.f4];
var sortedArray;
sortedArray = sort(inArray);
for(var i in sortedArray)
if (sortedArray[i] > 0) break;        
return sortedArray[i];

As Arcacde is a new scripting language I have found this test page very useful when trying to work out what you want, especially if you are porting from Python.

| improve this answer | |

I also asked this question on Esri’s GeoNet forum and wanted to share the solution that xander_bakker came up with:

var minv = 99999; 
var arr = [$feature.FromAddr_L, $feature.ToAddr_L, $feature.FromAddr_R, $feature.ToAddr_R];
    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; }
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.