<?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: featurelayer.calculate variable append in calc_expression in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/featurelayer-calculate-variable-append-in-calc/m-p/1215556#M7796</link>
    <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I have usually avoided &lt;FONT face="courier new,courier"&gt;calculate&lt;/FONT&gt; because it is much slower than using dataframes and&amp;nbsp;&amp;nbsp;&lt;FONT face="courier new,courier"&gt;edit_features&lt;/FONT&gt;&amp;nbsp;to perform updates, but here's the syntax for string concatenation (there are 2 ways I know of):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fl.calculate(where="1=1", calc_expression={"field": "test", "sqlExpression" : 'Activity || Description'})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OR&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fl.calculate(where="1=1", calc_expression={"field": "test", "sqlExpression" : 'CONCAT(Activity, Description)'})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This examples assumes you are calculating a field "test" to be the concatenation of fields "Activity" and "Description." In your case, it seems you actually have a variable?&lt;/P&gt;&lt;P&gt;In that case, you have to do some string substitution. Here I make use of the f-strings (introduced at Python 3.6):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fl.calculate(where="1=1", calc_expression={"field": "test", "sqlExpression" : f"CONCAT(Activity, '{newVal}')"})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
    <pubDate>Fri, 23 Sep 2022 16:00:44 GMT</pubDate>
    <dc:creator>EarlMedina</dc:creator>
    <dc:date>2022-09-23T16:00:44Z</dc:date>
    <item>
      <title>featurelayer.calculate variable append in calc_expression</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/featurelayer-calculate-variable-append-in-calc/m-p/1215222#M7791</link>
      <description>&lt;P&gt;I am trying to update rows of a field on a hosted feature layer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fl.calculate(where="1=1", calc_expression={"field": "Description", "value" : appendval })

fl.calculate(where="1=1", calc_expression={"field": "Description", "sqlExpression" : "SignShape"})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both of the above work.&amp;nbsp; The first one will calculate the "Description" field to the value of the variable appendval.&lt;/P&gt;&lt;P&gt;The second one will calculate the "Description" field with the value from the "SignShape" field.&lt;/P&gt;&lt;P&gt;What I need to do is calculate the "Description" field with the value from the "SignShape" field and the value from appendval concatenated to it as shown below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fl.calculate(where="1=1", calc_expression={"field": "Description", "sqlExpression" : "SignShape" + newval})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, it seems I can use the "sqlExpression" to utilize values from the field itself, OR, "value" to utilize a variable or other value.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea on how I can combine the two to get the desired results?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;value from "SignShape" field = 'Generic Sign'
appenval = 'Updated'

the value I want to insert would be:
"Generic Sign - Updated"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any suggestions,&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Sep 2022 18:58:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/featurelayer-calculate-variable-append-in-calc/m-p/1215222#M7791</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-09-22T18:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: featurelayer.calculate variable append in calc_expression</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/featurelayer-calculate-variable-append-in-calc/m-p/1215547#M7795</link>
      <description>&lt;P&gt;How about some better documentation on how this is supposed to work?&lt;/P&gt;&lt;P&gt;In the&amp;nbsp;arcgis.features module, show a single format as:&lt;/P&gt;&lt;LI-CODE lang="java"&gt;{“field” : “&amp;lt;field name&amp;gt;”, “value” : “&amp;lt;value&amp;gt;”}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;But shows two examples:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;calc_expression={"field": "ZONE", "value" : "R1"}
calc_expression={"field": "A",  "sqlExpression" : "B*3"}&lt;/LI-CODE&gt;&lt;P&gt;And references the REST API shows the same two examples, but shows the syntax format as:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;"calcExpression":[{"field": &amp;lt;fieldname&amp;gt;, "value" | "sqlExpression": &amp;lt;value&amp;gt; | "expression"},...]&lt;/LI-CODE&gt;&lt;P&gt;Which suggests the expression can be Field/Value&amp;nbsp; OR&amp;nbsp; sqlExpression/Value&amp;nbsp; OR&amp;nbsp; expression,...&lt;/P&gt;&lt;P&gt;Is "expression" available in the API, and if so, does anyone have example of "expression" format, since that doesn't seem to be listed anywhere?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2022 15:41:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/featurelayer-calculate-variable-append-in-calc/m-p/1215547#M7795</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-09-23T15:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: featurelayer.calculate variable append in calc_expression</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/featurelayer-calculate-variable-append-in-calc/m-p/1215556#M7796</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;I have usually avoided &lt;FONT face="courier new,courier"&gt;calculate&lt;/FONT&gt; because it is much slower than using dataframes and&amp;nbsp;&amp;nbsp;&lt;FONT face="courier new,courier"&gt;edit_features&lt;/FONT&gt;&amp;nbsp;to perform updates, but here's the syntax for string concatenation (there are 2 ways I know of):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fl.calculate(where="1=1", calc_expression={"field": "test", "sqlExpression" : 'Activity || Description'})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OR&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fl.calculate(where="1=1", calc_expression={"field": "test", "sqlExpression" : 'CONCAT(Activity, Description)'})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This examples assumes you are calculating a field "test" to be the concatenation of fields "Activity" and "Description." In your case, it seems you actually have a variable?&lt;/P&gt;&lt;P&gt;In that case, you have to do some string substitution. Here I make use of the f-strings (introduced at Python 3.6):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fl.calculate(where="1=1", calc_expression={"field": "test", "sqlExpression" : f"CONCAT(Activity, '{newVal}')"})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2022 16:00:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/featurelayer-calculate-variable-append-in-calc/m-p/1215556#M7796</guid>
      <dc:creator>EarlMedina</dc:creator>
      <dc:date>2022-09-23T16:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: featurelayer.calculate variable append in calc_expression</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/featurelayer-calculate-variable-append-in-calc/m-p/1215561#M7797</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;There&amp;nbsp;&lt;EM&gt;is&lt;/EM&gt; documentation, but perhaps it's not completely obvious. Since Enterprise/AGOL relies on ArcGIS Server, this documentation on supported SQL operations applies:&lt;/P&gt;&lt;P&gt;&lt;A href="https://enterprise.arcgis.com/en/server/latest/administer/windows/about-standardized-queries.htm" target="_blank" rel="noopener"&gt;Enforce standardized SQL queries—ArcGIS Server | Documentation for ArcGIS Enterprise&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Additionally, this documentation for Pro applies:&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/mapping/navigation/sql-reference-for-elements-used-in-query-expressions.htm" target="_blank" rel="noopener"&gt;SQL reference for query expressions used in ArcGIS—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2022 16:00:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/featurelayer-calculate-variable-append-in-calc/m-p/1215561#M7797</guid>
      <dc:creator>EarlMedina</dc:creator>
      <dc:date>2022-09-23T16:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: featurelayer.calculate variable append in calc_expression</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/featurelayer-calculate-variable-append-in-calc/m-p/1215631#M7807</link>
      <description>&lt;P&gt;Thanks for the suggestions.&amp;nbsp; I tried the .format method earlier but couldn't get it to work.&lt;/P&gt;&lt;P&gt;However, the f-string method seems to be working as expected.&amp;nbsp; Thanks again for that!!!!!&lt;/P&gt;&lt;P&gt;the calculate works pretty well for me, except of course when the AGOL servers throw a bad gateway error right in the middle (still not sure what/how/why that means, but have modified my script(s) to keep track of what has been updated and keep trying until it finishes).&lt;/P&gt;&lt;P&gt;I looked at dataframes a bit, but that seemed even more confusing that the basic calc function, and not sure how to approach it using edit and df's.&lt;/P&gt;&lt;P&gt;Basically, I have a dictionary of Code[Values].&amp;nbsp; I need to go trough every matching record, in the FC, if the Code matches my MUTCDcode field, then populate the Description field with the dictionary values as such:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;for mc in MCodeList:
          if DescrDict[mc]:
                    sqlclause = "MUTCDcode LIKE 'D3-1 %'"
                    (fl.calculate(where=sqlclause, calc_expression={"field": "Description", "value" : DescrDict[mc]}))&lt;/LI-CODE&gt;&lt;P&gt;which is working fine.&amp;nbsp; However, this will overwrite any data that is currently in that field.&lt;/P&gt;&lt;P&gt;For certain MUTCDcodes (LIKE 'D3-1 %'), If there is already a value in the Description field, I need to keep the data that is there and append the text result of the newValue variable to the end of the existing description.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does this still sound like something better handled with edit and df's?&amp;nbsp; If so, any chance you can point me towards a similar example (pull data from dictionary to update cell values)?&lt;/P&gt;&lt;P&gt;Thanks again for the help,&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Sep 2022 17:44:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/featurelayer-calculate-variable-append-in-calc/m-p/1215631#M7807</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-09-23T17:44:37Z</dc:date>
    </item>
  </channel>
</rss>

