I am not able to use IF condition in filed calculator ?

946
8
Jump to solution
03-16-2017 10:48 PM
ArpitSingh
New Contributor

    

Here I have created a new field named GS which has values from the field V_type but there are some missing values in field V_type so i want to fill the GS filed with another field named Location

How should i proceed with this?

0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

since this was a on-off, the easiest way is to do a quick select-by-attributes to get the records that are 'empty', then use the field calculator with newfield=oldfield because the field calculator only works on selected records rather all records.  This saves you the hastle of trying to come up with a field calculation function that accounts for 1 space, no spaces, non-printable characters etc.

View solution in original post

8 Replies
JayantaPoddar
MVP Esteemed Contributor

What you think about the following steps:

1. Use Select by Attributes: where V_Type = " " (Choose the blank value/values from the list of unique values).

2. Once the records are selected, populate the GS field with the values of the alternate field using field calculator.



Think Location
ArpitSingh
New Contributor

Is there any possibility that i can use IF condition in field calculation?

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

Click on Get Unique Values and select the blank value from there.



Think Location
ArpitSingh
New Contributor

Thanks, I done it 

It seems that we have a problem in using IF condition either through VB or by Python 

0 Kudos
DanPatterson_Retired
MVP Emeritus

Where is the 'if' statement? Are you using this as an example for an outside program?  If so and those blanks cells weren't spaces, then they would have been represented as such ( '' ) whereas in a geodatabase I would have expected to see a null representation.  There are ways to check for these conditions with if statements if you are using python in a separately called program

0 Kudos
ArpitSingh
New Contributor

Since I am using the shape file which has been created by some other person , due to some technical reasons while making of the shape file he has put some blanks in V_type field (as you can it in first picture). Now I created a new field (GS) which has the values same as V_type and where there is blank in V_type I was trying to put the value from Location field, So In the field calculation I was trying to use the If condition 

General logic for If condition was 

new field(GS) = V_type if V_type is blank/Null then GS = Location 

I was trying to use this logic in field calculation which seems to be not possible.

0 Kudos
DanPatterson_Retired
MVP Emeritus

since this was a on-off, the easiest way is to do a quick select-by-attributes to get the records that are 'empty', then use the field calculator with newfield=oldfield because the field calculator only works on selected records rather all records.  This saves you the hastle of trying to come up with a field calculation function that accounts for 1 space, no spaces, non-printable characters etc.

DanPatterson_Retired
MVP Emeritus

You didn't press the Get Unique values button, otherwise there would be a list of unique values listed.  That whole expression can be created without typing and the " " should be in single quotes ' '  if you had selected from the unique values.  Also, you need to press the Verify button to verify the expression, it sometimes yields better error messages.