Select to view content in your preferred language

# Calculate raito

1110
6
09-21-2020 08:23 AM
Frequent Contributor

I need to calculate ratio between two numbers than to percent but some rows in both field1 and field2 have zero values.

Simple calculator field2 / field1 * 100 but field1 has zeros, how do I by pass the rows with zeros in field1 in field calculator?

Field 1   field 2

0            15200 --> can't divide 0/15200

1 Solution

Accepted Solutions
MVP Esteemed Contributor

Put the following in the expression box using a Python parser:

``!field2!/!field1!*100 if !field1! else None‍``
6 Replies
MVP Emeritus

Are you doing this in python or just the field calculator?  Either way, select out those records that meet your criteria then apply the calculation.

That should just about do it....
Frequent Contributor

Ya I could have done it that way but I want to know who to do it through field calculator.

MVP Esteemed Contributor

Put the following in the expression box using a Python parser:

``!field2!/!field1!*100 if !field1! else None‍``
Frequent Contributor

I get "There was a failure during processing". Error 999999 & the field is not nullable.

Some rows do have zero if both fields.

MVP Alum

Try replacing the None in Joshua Bixby‌'s line of code with 0.

Frequent Contributor

Not sure why I didn't think of that big give away "field is not nullable."