# Calculate Field if/else statement returns nothing

I have to generate line dimension annotation for our maps as a part of my daily workflow. As it stands, I've been using

`round(float(!Distance!), 2)`

for straight lines, then switching the selection in the table to reselect the curve lines and running

`round(float(!ArcLength!), 2)`

in the Field Calculator geoprocessing tool to take the raw values and round them to two digits. I am trying to figure out a way to write an if/then statement so I only have to run the geoprocessing tool once.

This if/else statement doesn't return an error, but it doesn't calculate anything to the field. I haven't been able to find an example anywhere of what I'm trying to do. I'm assuming it's impossible, but there might be something I'm missing? I don't have any other options right now but to generate text annotation, using dynamic labeling will not work for our purposes. Currently using ArcMap 10.6.

``````def dimCalc(Distance,ArcLength):
if (Distance == 0):
return round(float(ArcLength),2)
else:
return round(float(Distance),2)
``````
• There is no "switch" in your code, how are you altering the selection between curved and straight lines? Nov 29, 2022 at 15:16
• A curved line will have a 0 in the Distance field. Curves in my dataset are defined by ArcLength and Radius. Distance is reserved for straight lines. Nov 30, 2022 at 16:24
• Your question says that you have a selection in the table. If that is the case, then clear (de-select) the selection. Field calculator will only work on selected records (if there is a selection). Nov 30, 2022 at 23:11
• What is the 'Expression' in your field calculator? If you replace the two `return` statements with `return 1` and `return 2`, respectively, what happens then? If you replace the entire contents of your `dimCalc()` function with `return 3`, what happens then? Nov 30, 2022 at 23:13

Are you sure distance is 0, maybe it's None/Null. Try this

``````def dimCalc(Distance,ArcLength):
if (Distance == 0 or Distance is None):
return round(float(ArcLength),2)
else:
return round(float(Distance),2)
``````

Also make sure you are passing the fields correctly as you haven't shown this in your question

``````dimCalc ( !distance!, !arclength! )
``````
• you are correct, the Distance field is Null if there's no value. I reran the tool with that script, and it didn't fail but it didn't populate the field. Thanks! edit: I did pass the fields as you described in both the original attempt and with the updated script. Dec 1, 2022 at 16:37