Calculate raito

387
6
Jump to solution
09-21-2020 08:23 AM
CCWeedcontrol
Regular 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

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

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

!field2!/!field1!*100 if !field1! else None

View solution in original post

6 Replies
JoeBorgione
MVP Esteemed Contributor

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.

can't wait to retire....
0 Kudos
CCWeedcontrol
Regular Contributor

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

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

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

!field2!/!field1!*100 if !field1! else None

View solution in original post

CCWeedcontrol
Regular Contributor

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

Some rows do have zero if both fields.

0 Kudos
RandyBurton
MVP Regular Contributor

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

CCWeedcontrol
Regular Contributor

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

0 Kudos