<?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 Calculate Field with Functions &amp;amp; values from other Fields in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/calculate-field-with-functions-amp-values-from/m-p/1397422#M9777</link>
    <description>&lt;P&gt;I'm sure I'm missing something simple.&amp;nbsp; I am just trying to use the API for python to update attributes using functions and values from other fields; but haven't been successful in formatting the the statement correct.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def getTotalDays(load,start):
 delta = load-start
 days = delta.days
 if days ==0:
  return 1
 else:
  return days

calc_dict['field'] = 'totaldays'
#This is not correct: 
calc_dict['sqlExpression'] = 'getTotalDays(!{0}!,!{1}!)'.format("dateloadedenterprise","surveydatestart")
result = compliance_svc_lyr.calculate(where=where,calc_expression=calc_dict)&lt;/LI-CODE&gt;&lt;P&gt;Additionally, I previously used dataframes to update the service, however had the same error as noted &lt;A href="https://community.esri.com/t5/arcgis-api-for-python-questions/issue-with-datetime-field-after-converting/td-p/1373700" target="_self"&gt;in this post&lt;/A&gt;, so I'm resorting back to field calculations.&lt;/P&gt;</description>
    <pubDate>Mon, 18 Mar 2024 17:58:42 GMT</pubDate>
    <dc:creator>usace_sam_rd3</dc:creator>
    <dc:date>2024-03-18T17:58:42Z</dc:date>
    <item>
      <title>Calculate Field with Functions &amp; values from other Fields</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/calculate-field-with-functions-amp-values-from/m-p/1397422#M9777</link>
      <description>&lt;P&gt;I'm sure I'm missing something simple.&amp;nbsp; I am just trying to use the API for python to update attributes using functions and values from other fields; but haven't been successful in formatting the the statement correct.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def getTotalDays(load,start):
 delta = load-start
 days = delta.days
 if days ==0:
  return 1
 else:
  return days

calc_dict['field'] = 'totaldays'
#This is not correct: 
calc_dict['sqlExpression'] = 'getTotalDays(!{0}!,!{1}!)'.format("dateloadedenterprise","surveydatestart")
result = compliance_svc_lyr.calculate(where=where,calc_expression=calc_dict)&lt;/LI-CODE&gt;&lt;P&gt;Additionally, I previously used dataframes to update the service, however had the same error as noted &lt;A href="https://community.esri.com/t5/arcgis-api-for-python-questions/issue-with-datetime-field-after-converting/td-p/1373700" target="_self"&gt;in this post&lt;/A&gt;, so I'm resorting back to field calculations.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 17:58:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/calculate-field-with-functions-amp-values-from/m-p/1397422#M9777</guid>
      <dc:creator>usace_sam_rd3</dc:creator>
      <dc:date>2024-03-18T17:58:42Z</dc:date>
    </item>
  </channel>
</rss>

