<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Field Calclator Issue (if Statement?) in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/field-calclator-issue-if-statement/m-p/229734#M7950</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello All,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to fill data in a field through Model Builder which requires me to concatenate data from two fields and then separate the data with a hyphen.&amp;nbsp; The issue I have is that in many cases, the second field has no data and thus, there is no point to having a hyphen.&amp;nbsp; Is there a relatively simple if statement that could handle this issue?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for your help in advance!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Colter&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 14 Dec 2011 20:01:05 GMT</pubDate>
    <dc:creator>ColterSikora1</dc:creator>
    <dc:date>2011-12-14T20:01:05Z</dc:date>
    <item>
      <title>Field Calclator Issue (if Statement?)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calclator-issue-if-statement/m-p/229734#M7950</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello All,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to fill data in a field through Model Builder which requires me to concatenate data from two fields and then separate the data with a hyphen.&amp;nbsp; The issue I have is that in many cases, the second field has no data and thus, there is no point to having a hyphen.&amp;nbsp; Is there a relatively simple if statement that could handle this issue?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for your help in advance!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Colter&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 Dec 2011 20:01:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calclator-issue-if-statement/m-p/229734#M7950</guid>
      <dc:creator>ColterSikora1</dc:creator>
      <dc:date>2011-12-14T20:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calclator Issue (if Statement?)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calclator-issue-if-statement/m-p/229735#M7951</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dear Colter,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm stuck with almost the same problem. Did u find a solution?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thx greetings&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Philipp&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Dec 2011 13:20:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calclator-issue-if-statement/m-p/229735#M7951</guid>
      <dc:creator>PSch</dc:creator>
      <dc:date>2011-12-21T13:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calclator Issue (if Statement?)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calclator-issue-if-statement/m-p/229736#M7952</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It depends if the second field contains Null values or whitespace characters or a mixture of the two.&amp;nbsp; Assuming it is a mixture (and that the first field does not also need to be tested for blank or Null) try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Dim Output
If IsNull([MyField2]) Then
&amp;nbsp; Output = [MyField1]
Elseif Trim([MyField2]) = "" Then
&amp;nbsp; Output = [MyField1]
Else
&amp;nbsp; Output = [MyField1] &amp;amp; "-" &amp;amp; [MyField2]
End If&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you plan on exporting to a Python script than this needs to be rewritten in Python to work.&amp;nbsp; &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/23718-Python-Field-Calculator-Null-Values?highlight=python+Null+test" rel="nofollow noopener noreferrer" target="_blank"&gt;However, this post suggests that Python cannot test for Null values in the field calculator like VB Script can and that you should use a cursor instead for that condition.&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:10:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calclator-issue-if-statement/m-p/229736#M7952</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2021-12-11T11:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: Field Calclator Issue (if Statement?)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/field-calclator-issue-if-statement/m-p/229737#M7953</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Python does allow for &amp;lt;null&amp;gt; check in field calculator.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Open field calculator, choose the Python Parser.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Check the "Show Codeblock" box&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Enter the following in the "Pre-Logic Script Code:" box&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def Concatenate(field1,field2):
&amp;nbsp; if field2 == "":
&amp;nbsp;&amp;nbsp;&amp;nbsp; return field1
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; return field1 + '-' + field2&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;in the bottom box enter (change the stuff between the !'s to your actual field names):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Concatenate(str(!MyField1!), str(!MyField2!))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This works because the null values ( &amp;lt;null&amp;gt; ) are converted to empty strings before being sent to the custom "Concatenate" function build in the code block. More info can be found at &lt;/SPAN&gt;&lt;A href="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/2010/08/30/Concatenate.aspx" rel="nofollow noopener noreferrer" target="_blank"&gt;this link&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Additional options:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if both fields contain &amp;lt;null&amp;gt; values and/or you want to you want to retain said &amp;lt;null&amp;gt; values... this example code should help:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Parser: Python&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;PreLogic:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def myFunction(one,two):
&amp;nbsp; if one == "":&amp;nbsp;&amp;nbsp; # check if first field is &amp;lt;null&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; if two == "": # check if both fields are &amp;lt;null&amp;gt; and returns &amp;lt;null&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pass
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return two&amp;nbsp;&amp;nbsp; # otherwise, just return the second field value
&amp;nbsp; else:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # check if the first field is populated...
&amp;nbsp;&amp;nbsp;&amp;nbsp; if two == "": # if second field is blank
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return one&amp;nbsp; # return just the first field
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # if both fields are populated
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return one + "-" + two&amp;nbsp; # return a concatenation of the fields with a hyphen deliminator&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Calculation box:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;myFunction(str(!field1!), str(!field2!))&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 11:10:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/field-calclator-issue-if-statement/m-p/229737#M7953</guid>
      <dc:creator>RobertJones6</dc:creator>
      <dc:date>2021-12-11T11:10:23Z</dc:date>
    </item>
  </channel>
</rss>

