# Calculating Min and Max Across fields while skipping Zeros

I am using ArcGIS Desktop 10.5 here. I have a streets layer that has address ranges in the fields FromLeft, ToLeft, FromRight, and ToRight. I am trying to create a street index csv that has the low and high values for each street. I'm trying to calculate the min and max values across the 4 fields and calculate those into 2 new fields called MIN and MAX.

I used `min( !FromLeft!, !FromRight!, !ToLeft!, !ToRight!)` to get the minimum values.

The only thing is that some streets have 0 in one or more of these 4 fields. I would like to skip the value 0 from this calculation and only consider non-zero numbers.

Can this be done using the field calculator?

All my fields are LONGs.

Maybe there are easier ways, but here's one using Python.

1. In the Field Calculator window, select the Python parser
2. Check Show Codeblock
3. The Pre-logic Script code defines a method that returns only values greater than 0.
``````def greater_than_0 (value):
return value > 0
``````
1. The code for the MIN field is
``````min (filter (greater_than_0, [ !FromLeft!, !FromRight!, !ToLeft!, !ToRight! ]))
``````

Note that this code will fail if all fields contain 0 values. If you have those, you may want to make a feature selection to exclude those records first

Here's a screenshot (Never mind my fieldnames, I used a scrap shapefile)

• Thanks! Worked like a charm. Jul 15, 2020 at 13:46
• I can't get this code to work in ArcGIS Pro (python 9.3). Is there a difference? It seems to me the field calculator doesn't like this use of python's filter function? As soon as I add the 'filter', I get an error that says "No function was found with the name 'min' (even though the 'min' function works just fine when I don't employ 'filter'). Feb 10 at 15:29