<?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: Using Conditional Statements to add from different fields in Field Calculator (Python) in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/using-conditional-statements-to-add-from-different/m-p/1030181#M37862</link>
    <description>&lt;P&gt;Genius. Thank you. I was making it more difficult than I should have.&lt;/P&gt;&lt;P&gt;What if I had several attributes for MAINTENANCETYPE?&lt;/P&gt;&lt;P&gt;When I try to use this below, it populates all fields with the difference of DEFMAINTENANCE - COST even if it doesn't meet the criteria:&lt;/P&gt;&lt;P&gt;!DEFMAINTENANCE! - !COST! if !MAINTENANCETYPE! == 'DM General' or 'DM Asset Protection' or 'DM Priority Safety Concern' else !MAINTENANCECOMPLETE!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any way to do this&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1371"&gt;@JoshuaBixby&lt;/a&gt;&amp;nbsp;?&lt;/P&gt;</description>
    <pubDate>Tue, 02 Mar 2021 20:24:22 GMT</pubDate>
    <dc:creator>JoshBillings</dc:creator>
    <dc:date>2021-03-02T20:24:22Z</dc:date>
    <item>
      <title>Using Conditional Statements to add from different fields in Field Calculator (Python)</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/using-conditional-statements-to-add-from-different/m-p/1030074#M37848</link>
      <description>&lt;P&gt;Hey all,&lt;/P&gt;&lt;P&gt;I am new to Python. I am currently trying to write a calculation using Python in the field calculator ONLY IF another field equals a specific value.&lt;/P&gt;&lt;P&gt;For instance, I have a&amp;nbsp;&lt;STRONG&gt;MAINTENANCECOMPLETE&lt;/STRONG&gt; field, a &lt;STRONG&gt;MAINTENANCETYPE&lt;/STRONG&gt; field, a &lt;STRONG&gt;DEFMAINTENANCE&lt;/STRONG&gt; field, and a &lt;STRONG&gt;COST&lt;/STRONG&gt; field.&lt;/P&gt;&lt;P&gt;I want the &lt;STRONG&gt;MAINTENANCECOMPLETE&lt;/STRONG&gt; field to populate the sum of &lt;STRONG&gt;DEFMAINTENANCE&lt;/STRONG&gt; and &lt;STRONG&gt;COST &lt;/STRONG&gt;&lt;EM&gt;only if&amp;nbsp;&lt;/EM&gt;&lt;STRONG&gt;MAINTENANCETYPE&amp;nbsp;&lt;/STRONG&gt;is equal to "DM General."&lt;/P&gt;&lt;P&gt;Here is what I currently have:&lt;/P&gt;&lt;P&gt;Code Block:&lt;/P&gt;&lt;P&gt;def ifBlock(maintenanceType):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if maintenanceType== 'DM General'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return !DEFMAINTENANCE! - !Cost!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actual Code:&lt;/P&gt;&lt;P&gt;ifBlock(!MaintenanceType!)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How should I write this differently?&lt;/P&gt;&lt;P&gt;Let me know if I can clarify in any way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 17:04:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/using-conditional-statements-to-add-from-different/m-p/1030074#M37848</guid>
      <dc:creator>JoshBillings</dc:creator>
      <dc:date>2021-02-24T17:04:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using Conditional Statements to add from different fields in Field Calculator (Python)</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/using-conditional-statements-to-add-from-different/m-p/1030111#M37851</link>
      <description>&lt;P&gt;You don't have to use the code block for this, you can use Python conditional expression, a.k.a, ternary operator:&amp;nbsp; &lt;A href="https://docs.python.org/3/reference/expressions.html" target="_blank"&gt;6. Expressions — Python 3.9.2 documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Expression:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;!DEFMAINTENANCE! + !COST! if !MAINTENANCETYPE! == 'DM General' else !MAINTENANCECOMPLETE!&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 24 Feb 2021 18:26:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/using-conditional-statements-to-add-from-different/m-p/1030111#M37851</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-02-24T18:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using Conditional Statements to add from different fields in Field Calculator (Python)</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/using-conditional-statements-to-add-from-different/m-p/1030181#M37862</link>
      <description>&lt;P&gt;Genius. Thank you. I was making it more difficult than I should have.&lt;/P&gt;&lt;P&gt;What if I had several attributes for MAINTENANCETYPE?&lt;/P&gt;&lt;P&gt;When I try to use this below, it populates all fields with the difference of DEFMAINTENANCE - COST even if it doesn't meet the criteria:&lt;/P&gt;&lt;P&gt;!DEFMAINTENANCE! - !COST! if !MAINTENANCETYPE! == 'DM General' or 'DM Asset Protection' or 'DM Priority Safety Concern' else !MAINTENANCECOMPLETE!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any way to do this&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1371"&gt;@JoshuaBixby&lt;/a&gt;&amp;nbsp;?&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 20:24:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/using-conditional-statements-to-add-from-different/m-p/1030181#M37862</guid>
      <dc:creator>JoshBillings</dc:creator>
      <dc:date>2021-03-02T20:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using Conditional Statements to add from different fields in Field Calculator (Python)</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/using-conditional-statements-to-add-from-different/m-p/1032440#M38092</link>
      <description>&lt;P&gt;This should work:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;!DEFMAINTENANCE! - !COST! if !MAINTENANCETYPE! in ('DM General','DM Asset Protection','DM Priority Safety Concern') else !MAINTENANCECOMPLETE!&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 03 Mar 2021 15:29:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/using-conditional-statements-to-add-from-different/m-p/1032440#M38092</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-03-03T15:29:44Z</dc:date>
    </item>
  </channel>
</rss>

