<?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: Calculate field based on sum of other fields in Data Management Questions</title>
    <link>https://community.esri.com/t5/data-management-questions/calculate-field-based-on-sum-of-other-fields/m-p/585023#M33052</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you sum Nulls the result is Null even if most of the inputs are numbers.&amp;nbsp; You can filter out Nulls by using a code-block in field calculator with the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-family:Courier New;"&gt;Parser:&lt;BR /&gt;Python&lt;BR /&gt;&lt;BR /&gt;Expression:&lt;BR /&gt;null2z(!field1!) + null2z(!field2!) + ... + null2z(!fieldn!)&lt;BR /&gt;&lt;BR /&gt;Code Block:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def null2z(num):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if num:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return num
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0
&lt;/PRE&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can call the function whatever you want.&amp;nbsp; You can do the same thing in a python script: just copy in the above function, and wrap your inputs in the function call.&amp;nbsp; In python if you do an &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; on a value it returns false (takes the else branch) if the input value is Null.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PS: suggestion: test things on a small subset of your data (but don't save your edits) before running against your entire data set.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PPS: It might be faster to simply assign a 0 to all your Nulls.&amp;nbsp; YMMV&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 01:09:13 GMT</pubDate>
    <dc:creator>StormwaterWater_Resources</dc:creator>
    <dc:date>2021-12-12T01:09:13Z</dc:date>
    <item>
      <title>Calculate field based on sum of other fields</title>
      <link>https://community.esri.com/t5/data-management-questions/calculate-field-based-on-sum-of-other-fields/m-p/585022#M33051</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Working with a personal geodatabase, I am trying to calculated a field for a layer that contains 5000+ polygons based on the sum of 7 other fields.&amp;nbsp; I.e., every polygon has either a "1" or a "&amp;lt;null&amp;gt;" value in each of the 7 fields.&amp;nbsp; If one of the polygons has 4 "1" values and 3 "&amp;lt;null&amp;gt;" values, I want my new field to show a "4."&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When I carry out the calculate field command (sum_all= [field1]+[field2]...etc.) the program takes several hours to process the command, but no change occurs in the new (sum_all) field.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope that there is a simply solution, any help is much appreciated!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jacob&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Mar 2013 21:34:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/calculate-field-based-on-sum-of-other-fields/m-p/585022#M33051</guid>
      <dc:creator>JacobPederson</dc:creator>
      <dc:date>2013-03-18T21:34:24Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field based on sum of other fields</title>
      <link>https://community.esri.com/t5/data-management-questions/calculate-field-based-on-sum-of-other-fields/m-p/585023#M33052</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you sum Nulls the result is Null even if most of the inputs are numbers.&amp;nbsp; You can filter out Nulls by using a code-block in field calculator with the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-family:Courier New;"&gt;Parser:&lt;BR /&gt;Python&lt;BR /&gt;&lt;BR /&gt;Expression:&lt;BR /&gt;null2z(!field1!) + null2z(!field2!) + ... + null2z(!fieldn!)&lt;BR /&gt;&lt;BR /&gt;Code Block:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def null2z(num):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if num:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return num
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0
&lt;/PRE&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can call the function whatever you want.&amp;nbsp; You can do the same thing in a python script: just copy in the above function, and wrap your inputs in the function call.&amp;nbsp; In python if you do an &lt;/SPAN&gt;&lt;SPAN style="font-family:Courier New;"&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; on a value it returns false (takes the else branch) if the input value is Null.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PS: suggestion: test things on a small subset of your data (but don't save your edits) before running against your entire data set.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PPS: It might be faster to simply assign a 0 to all your Nulls.&amp;nbsp; YMMV&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:09:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/calculate-field-based-on-sum-of-other-fields/m-p/585023#M33052</guid>
      <dc:creator>StormwaterWater_Resources</dc:creator>
      <dc:date>2021-12-12T01:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field based on sum of other fields</title>
      <link>https://community.esri.com/t5/data-management-questions/calculate-field-based-on-sum-of-other-fields/m-p/585024#M33053</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This helps a bunch. Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Mar 2013 14:32:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-management-questions/calculate-field-based-on-sum-of-other-fields/m-p/585024#M33053</guid>
      <dc:creator>JacobPederson</dc:creator>
      <dc:date>2013-03-29T14:32:25Z</dc:date>
    </item>
  </channel>
</rss>

