<?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: Perform a SQL Count in Calculate Field in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1133983#M50044</link>
    <description>&lt;P&gt;Hello - thank you so much for your help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Info - I created a Field Map app for our deputies to use.&amp;nbsp;I have a feature layer with several fields and my thought is to use the calculate field to perform a count on specific columns. Basically counting the field, if there is text, count it as 1, add the counts and enter total count in my "Enter Total Number of Complaints" field.&lt;/P&gt;&lt;P&gt;I am in the Enterprise, go to the layer, go to data, find my field "entertotalnumberofcomplaints", click calculate on that field.&amp;nbsp; And based on the image below, I must use SQL.&amp;nbsp; The complaint fields are string and the 'enter total complaint number' field is numeric. Does that help?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AnnettePoole1_0-1642183301002.png" style="width: 479px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/31550iA610ABD901284E03/image-dimensions/479x52?v=v2" width="479" height="52" role="button" title="AnnettePoole1_0-1642183301002.png" alt="AnnettePoole1_0-1642183301002.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AnnettePoole1_1-1642183348296.png" style="width: 541px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/31551i24906646B16C5219/image-dimensions/541x341?v=v2" width="541" height="341" role="button" title="AnnettePoole1_1-1642183348296.png" alt="AnnettePoole1_1-1642183348296.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Jan 2022 18:05:29 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2022-01-14T18:05:29Z</dc:date>
    <item>
      <title>Perform a SQL Count in Calculate Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1133936#M50039</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;This seems like it should be very easy, but I cannot get this to work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to use SQL because I have layers with sync or keep track of created and updated features enabled.&lt;/P&gt;&lt;P&gt;In a nutshell, I created a column titled 'entertotalnocomplaints'.&amp;nbsp; Note, this is a field map app the deputies are using. As of right now the deputies must count the number of complaints received on one address and then enter the total into this column. I feel I should be able to count the number of complaint fields that have text and return that total count to the field 'entertotalnocomplaints'.&amp;nbsp; So count those with text and return a numeric number to the 'entertotalnocomplaints' field.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Upon some research of this forum this is what I have come up with so far, obviously it doesn't work. I would really appreciate some help. Thank you.&lt;/P&gt;&lt;P&gt;SQL statement that I put in the calculate field&lt;/P&gt;&lt;P&gt;entertotalnocomplaints =&lt;/P&gt;&lt;P&gt;def FieldCount(complaint, complaint1, complaint2, complaint3, complaint4, complaint5, complaint6, complaint7, complaint8, complaint9, complaint10):&lt;BR /&gt;fields = [complaint, complaint1, complaint2, complaint3, complaint4, complaint5, complaint6, complaint7,&amp;nbsp; complaint8, complaint9, complaint10]&lt;BR /&gt;return count&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 16:50:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1133936#M50039</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-01-14T16:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: Perform a SQL Count in Calculate Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1133946#M50041</link>
      <description>&lt;P&gt;That doesn't look like SQL to me.&lt;/P&gt;&lt;P&gt;It's hard to know how to write the expression without knowing about the underlying data structure, but if you've got 10 complaint fields, and you want to increment the count for each field with a value in it, try something like this:&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;(CASE WHEN CHAR_LENGTH(complaint1) &amp;gt; 0 THEN 1 ELSE 0 END) +
(CASE WHEN CHAR_LENGTH(complaint2) &amp;gt; 0 THEN 1 ELSE 0 END) +
... etc ... +
(CASE WHEN CHAR_LENGTH(complaint10) &amp;gt; 0 THEN 1 ELSE 0 END)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Probably not the most elegant approach, but SQL's not my primary language.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 17:18:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1133946#M50041</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-01-14T17:18:21Z</dc:date>
    </item>
    <item>
      <title>Re: Perform a SQL Count in Calculate Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1133954#M50043</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous User, I'm thinking this isn't exactly a SQL question with a "def" statement. I think that's a Python function. You could use something like this as a field calculate function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def getComplaintCount(complaint1, complaint2, complaint3, complaint4, complaint5, complaint6, complaint7, complaint8, complaint9, complaint10):
    compCount = 0
    compCount += 1 if complaint1 != None else 0
    compCount += 1 if complaint2 != None else 0
    compCount += 1 if complaint3 != None else 0
    compCount += 1 if complaint4 != None else 0
    compCount += 1 if complaint5 != None else 0
    compCount += 1 if complaint6 != None else 0
    compCount += 1 if complaint7 != None else 0
    compCount += 1 if complaint8 != None else 0
    compCount += 1 if complaint9 != None else 0
    compCount += 1 if complaint10 != None else 0

    return compCount&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This simply checks if each value is null and adds 1 to the compCount variable if it is not null. If your complaint fields are not nullable strings, you'd want to replace the "None" with a ''.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 17:32:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1133954#M50043</guid>
      <dc:creator>DougGreen</dc:creator>
      <dc:date>2022-01-14T17:32:50Z</dc:date>
    </item>
    <item>
      <title>Re: Perform a SQL Count in Calculate Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1133983#M50044</link>
      <description>&lt;P&gt;Hello - thank you so much for your help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Info - I created a Field Map app for our deputies to use.&amp;nbsp;I have a feature layer with several fields and my thought is to use the calculate field to perform a count on specific columns. Basically counting the field, if there is text, count it as 1, add the counts and enter total count in my "Enter Total Number of Complaints" field.&lt;/P&gt;&lt;P&gt;I am in the Enterprise, go to the layer, go to data, find my field "entertotalnumberofcomplaints", click calculate on that field.&amp;nbsp; And based on the image below, I must use SQL.&amp;nbsp; The complaint fields are string and the 'enter total complaint number' field is numeric. Does that help?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AnnettePoole1_0-1642183301002.png" style="width: 479px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/31550iA610ABD901284E03/image-dimensions/479x52?v=v2" width="479" height="52" role="button" title="AnnettePoole1_0-1642183301002.png" alt="AnnettePoole1_0-1642183301002.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AnnettePoole1_1-1642183348296.png" style="width: 541px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/31551i24906646B16C5219/image-dimensions/541x341?v=v2" width="541" height="341" role="button" title="AnnettePoole1_1-1642183348296.png" alt="AnnettePoole1_1-1642183348296.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 18:05:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1133983#M50044</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-01-14T18:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: Perform a SQL Count in Calculate Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1133989#M50045</link>
      <description>&lt;P&gt;Hello, this makes sense. I added this to the calculate field, but I get calculate expression is not valid.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do see a functions field and count function is not in it. I wonder if this calculate field only performs the functions in this list?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AnnettePoole1_2-1642183932991.png" style="width: 269px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/31555iEDC61787C3EDB347/image-dimensions/269x429?v=v2" width="269" height="429" role="button" title="AnnettePoole1_2-1642183932991.png" alt="AnnettePoole1_2-1642183932991.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you Doug!&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 18:13:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1133989#M50045</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-01-14T18:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: Perform a SQL Count in Calculate Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1133990#M50046</link>
      <description>&lt;P&gt;Makes sense, thank you for elaborating. Did you try the expression I posted? It worked in a quick test I did.&lt;/P&gt;&lt;P&gt;I believe if you run the field calculation in ArcGIS Pro or in a Python environment, you have access to other calculation methods, if that's useful to you.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 18:13:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1133990#M50046</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-01-14T18:13:27Z</dc:date>
    </item>
    <item>
      <title>Re: Perform a SQL Count in Calculate Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1133993#M50047</link>
      <description>&lt;P&gt;Oh, ok. You might be able to pull the feature class into Pro and perform a field calculation on it using the previous python but i think&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;had the right idea then. Only catch there is that if any of the values are NULL, you would get a NULL. So you could use this to change any empty strings to NULL and add 1 if not NULL.&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;IIF(NULLIF(complaint1, '') IS NULL, 0, 1) +
IIF(NULLIF(complaint2, '') IS NULL, 0, 1) +
IIF(NULLIF(complaint3, '') IS NULL, 0, 1) +
IIF(NULLIF(complaint4, '') IS NULL, 0, 1) +
IIF(NULLIF(complaint5, '') IS NULL, 0, 1) +
IIF(NULLIF(complaint6, '') IS NULL, 0, 1) +
IIF(NULLIF(complaint7, '') IS NULL, 0, 1) +
IIF(NULLIF(complaint8, '') IS NULL, 0, 1) +
IIF(NULLIF(complaint9, '') IS NULL, 0, 1) +
IIF(NULLIF(complaint10, '') IS NULL, 0, 1)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 14 Jan 2022 18:16:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1133993#M50047</guid>
      <dc:creator>DougGreen</dc:creator>
      <dc:date>2022-01-14T18:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: Perform a SQL Count in Calculate Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1133995#M50048</link>
      <description>&lt;P&gt;Makes sense. So is this SQL or python that you and JCarlson are providing me? SQL?&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 18:21:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1133995#M50048</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-01-14T18:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Perform a SQL Count in Calculate Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1133999#M50049</link>
      <description>&lt;P&gt;Enclosing the CHAR_LENGTH function in a CASE will evaluate a 0 in the event of a null field.&lt;/P&gt;&lt;P&gt;And @Anonymous User&amp;nbsp; my expression was SQL, sorry for not specifying.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 18:29:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1133999#M50049</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-01-14T18:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: Perform a SQL Count in Calculate Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1134000#M50050</link>
      <description>&lt;P&gt;Yep, don't go off of mine ;). That was T-SQL for SQL. Didn't realize it was only a subset of SQL in that window.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 18:31:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1134000#M50050</guid>
      <dc:creator>DougGreen</dc:creator>
      <dc:date>2022-01-14T18:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: Perform a SQL Count in Calculate Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1134003#M50051</link>
      <description>&lt;P&gt;Refer to this documentation to see what can/can't be done in AGOL SQL queries:&lt;/P&gt;&lt;P&gt;&lt;A href="https://doc.arcgis.com/en/arcgis-online/reference/sql-agol.htm" target="_blank"&gt;https://doc.arcgis.com/en/arcgis-online/reference/sql-agol.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 18:37:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1134003#M50051</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-01-14T18:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: Perform a SQL Count in Calculate Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1134012#M50053</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;it worked!&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/70326"&gt;@DougGreen&lt;/a&gt;&amp;nbsp;Thank you to both of you. Have a great weekend!&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jan 2022 18:54:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1134012#M50053</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-01-14T18:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Perform a SQL Count in Calculate Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1145436#M51673</link>
      <description>&lt;P&gt;Hello again! As mentioned I have a field I am using for calculate.&amp;nbsp; When I input your solution, it works. The number appears in the field correctly.&amp;nbsp; But now I discovered, when I added data via the Field Map or Collector, the calculate field is not updating. So I went back, and re entered it and it worked. It updated, but still doesn't update when data is input to the app. Strange. Any ideas why? I searched but do not see any.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Feb 2022 23:46:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1145436#M51673</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-02-17T23:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: Perform a SQL Count in Calculate Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1145620#M51691</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous User, I don't know why I didn't pick up on this before but of course you're wanting this to happen regularly. This solution that was provided here works whenever you go in and calculate the field. So Calculating a field in this way is a "one-and-done" type of thing. It's not setting up an automatic default value of sorts on the field. So as new records are added or any information changes on the record, you'd have to calculate the field to show the changes. I don't think you're going to want to do that regularly but you could set up a minimal python script to run once or twice a day that would calculate that field for you&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/2.8/tool-reference/data-management/calculate-field.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/2.8/tool-reference/data-management/calculate-field.htm&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 15:12:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1145620#M51691</guid>
      <dc:creator>DougGreen</dc:creator>
      <dc:date>2022-02-18T15:12:17Z</dc:date>
    </item>
    <item>
      <title>Re: Perform a SQL Count in Calculate Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1145681#M51700</link>
      <description>&lt;P&gt;@Anonymous User, on an unrelated note, using "no" as an abbreviation for "number" in a field name isn't a good practice. For example your current field name is &lt;FONT face="courier new,courier"&gt;entertotalnocomplaints&lt;/FONT&gt;, which is intended to be read as "enter total number of compliants," but could be read as "enter total of no (or non) complaints."&amp;nbsp; Also, the field does not appear to be entered by the user directly so it is a bit confusing to start it with "enter."&amp;nbsp; I suggest a field name of "NumComplaints" or "ComplaintCount".&lt;/P&gt;</description>
      <pubDate>Fri, 18 Feb 2022 17:11:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1145681#M51700</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2022-02-18T17:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: Perform a SQL Count in Calculate Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1145683#M51701</link>
      <description>Thank you! I am learning that certain words do not belong in field names. Great point.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 18 Feb 2022 17:16:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/perform-a-sql-count-in-calculate-field/m-p/1145683#M51701</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-02-18T17:16:39Z</dc:date>
    </item>
  </channel>
</rss>

