<?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 Re: Null if Statement in Calculated Field in Data Management Questions</title>
    <link>https://community.esri.com/t5/data-management-questions/null-if-statement-in-calculated-field/m-p/572307#M32426</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;is it a decimal formatting issue ?&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 13 Feb 2020 12:33:54 GMT</pubDate>
    <dc:creator>ThomasKelly</dc:creator>
    <dc:date>2020-02-13T12:33:54Z</dc:date>
    <item>
      <title>Null if Statement in Calculated Field</title>
      <link>https://community.esri.com/t5/data-management-questions/null-if-statement-in-calculated-field/m-p/572303#M32422</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a column in an attribute table that has a mixture of nulls and data. I wish to create a new column that will return a "yes" if there is data in the column being checked and "no" if it is a null. I have tried a variety of python functions but I keep getting an error similar to the below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR 000539: File "&amp;lt;expression&amp;gt;", line 1&lt;BR /&gt; updateValue(1E+21.0)&lt;BR /&gt; ^&lt;BR /&gt;SyntaxError: invalid syntax&lt;BR /&gt; Failed to execute (CalculateField).&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried the following :&lt;/P&gt;&lt;P&gt;X = updateValue(!field!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def updateValue(value):&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;if value == None:&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;return 'no'&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;else: return "yes"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be most appreciated.&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Feb 2020 11:47:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/null-if-statement-in-calculated-field/m-p/572303#M32422</guid>
      <dc:creator>ThomasKelly</dc:creator>
      <dc:date>2020-02-13T11:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: Null if Statement in Calculated Field</title>
      <link>https://community.esri.com/t5/data-management-questions/null-if-statement-in-calculated-field/m-p/572304#M32423</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/blogs/dan_patterson/2016/08/14/script-formatting" target="_blank"&gt;/blogs/dan_patterson/2016/08/14/script-formatting&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;your indentation was wrong and the code block (eg lines 3-6 or 17-20 ) need to be placed in the code section and the expression (line 10 or 24) in the expression line.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Make the field (!some_field!) active, python parser, put in the code in the code block and the expression in its place and run.&lt;/P&gt;&lt;P&gt;Also don't use == None, use ... is None ...&lt;/P&gt;&lt;P&gt;you don't need your extra else since it will bypass to line 6 if value is not None&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;# for string field&lt;/SPAN&gt;

&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;updateValue&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;value&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
   &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; value &lt;SPAN class="keyword token"&gt;is&lt;/SPAN&gt; None&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
       &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'no'&lt;/SPAN&gt;
   &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"yes"&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;# calling expression&lt;/SPAN&gt;


updateValue&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;!some_field!&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;


&lt;SPAN class="comment token"&gt;# ------------------------&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;# for numeric field&lt;/SPAN&gt;


&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;updateValue&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;value&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
   &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; value &lt;SPAN class="keyword token"&gt;is&lt;/SPAN&gt; None&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
       &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;999&lt;/SPAN&gt;
   &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; value

&lt;SPAN class="comment token"&gt;# calling expression&lt;/SPAN&gt;

updateValue&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;!some_field!&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:38:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/null-if-statement-in-calculated-field/m-p/572304#M32423</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-12T00:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: Null if Statement in Calculated Field</title>
      <link>https://community.esri.com/t5/data-management-questions/null-if-statement-in-calculated-field/m-p/572305#M32424</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for the response, I have tried both of these and whilst both expressions are valid I am still returning the following for both:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ERROR 000539: File "&amp;lt;expression&amp;gt;", line 1&lt;BR /&gt; updateValue(1E+21.0)&lt;BR /&gt; ^&lt;BR /&gt;SyntaxError: invalid syntax&lt;BR /&gt; Failed to execute (CalculateField).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The (!some_field!) is of data type double ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I cannot understand why the same error is returning, it should be a straightforward process.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thomas&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Feb 2020 12:15:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/null-if-statement-in-calculated-field/m-p/572305#M32424</guid>
      <dc:creator>ThomasKelly</dc:creator>
      <dc:date>2020-02-13T12:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: Null if Statement in Calculated Field</title>
      <link>https://community.esri.com/t5/data-management-questions/null-if-statement-in-calculated-field/m-p/572306#M32425</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="number token"&gt;1e2&lt;/SPAN&gt;
&lt;SPAN class="number token"&gt;100.0&lt;/SPAN&gt;

&lt;SPAN class="number token"&gt;1e2.0&lt;/SPAN&gt;
  File &lt;SPAN class="string token"&gt;"&amp;lt;ipython-input-2-3dea3e3816b2&amp;gt;"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; line &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;
    &lt;SPAN class="number token"&gt;1e2.0&lt;/SPAN&gt;
        &lt;SPAN class="operator token"&gt;^&lt;/SPAN&gt;
SyntaxError&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; invalid syntax&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;spot the difference?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:38:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/null-if-statement-in-calculated-field/m-p/572306#M32425</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-12T00:38:40Z</dc:date>
    </item>
    <item>
      <title>Re: Null if Statement in Calculated Field</title>
      <link>https://community.esri.com/t5/data-management-questions/null-if-statement-in-calculated-field/m-p/572307#M32426</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;is it a decimal formatting issue ?&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Feb 2020 12:33:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/null-if-statement-in-calculated-field/m-p/572307#M32426</guid>
      <dc:creator>ThomasKelly</dc:creator>
      <dc:date>2020-02-13T12:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: Null if Statement in Calculated Field</title>
      <link>https://community.esri.com/t5/data-management-questions/null-if-statement-in-calculated-field/m-p/572308#M32427</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This question seems to come up in one form or another about every 6 months on GeoNet.&amp;nbsp; I think it is important to understand what Dan is pointing out.&amp;nbsp; Additionally, you can use a Python conditional expression to achieve the result while not needing to define a code block:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="string token"&gt;"NO"&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; !field! &lt;SPAN class="keyword token"&gt;is&lt;/SPAN&gt; None &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"YES"&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Feb 2020 15:24:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/null-if-statement-in-calculated-field/m-p/572308#M32427</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2020-02-13T15:24:09Z</dc:date>
    </item>
  </channel>
</rss>

