<?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: Calculation error using cursors, second cursor uses first value of first cursor in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/calculation-error-using-cursors-second-cursor-uses/m-p/139659#M10901</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;That doesn't make sense - can you post some of your data?&lt;BR /&gt;&lt;BR /&gt;I have not tested further, but the only thing I can think of at this point is possibly an indention error with this block, corrected below (this time I am using tabs):&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for Row in TheOnlyCursorNeeded:
 if Row[0] == "Example 1":
&amp;nbsp; totalPrice1 += (Row[1])
 elif Row[0] == "Example 2":
&amp;nbsp; totalPrice2 += (Row[1])
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Your suggestion worked perfectly, It was a selection error on my part while troubleshooting.&amp;nbsp; thank you&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 07:43:06 GMT</pubDate>
    <dc:creator>jasonfargo</dc:creator>
    <dc:date>2021-12-11T07:43:06Z</dc:date>
    <item>
      <title>Calculation error using cursors, second cursor uses first value of first cursor</title>
      <link>https://community.esri.com/t5/python-questions/calculation-error-using-cursors-second-cursor-uses/m-p/139655#M10897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Attempting to add up values of one field based on the value of another field.&amp;nbsp; The first cursor adds up the values in the field correctly, but the second one uses the first value of the first cursor resulting in a wrong total.&amp;nbsp; If I replace the code "totalPrice1 = (Row[1])" with "totalPrice1 = 0.0", it just skips the first value entirely. I think the error lies in this code in the second cursor "totalPrice2 = (Row[1])" because it seems to set the value to the first value in the first cursor instead of the first value in the second.&amp;nbsp; ideas?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Fields = ['Field1','Dollar Value'] FirstCursor = arcpy.da.SearchCursor(fcName,Fields) for Row in FirstCursor: &amp;nbsp;&amp;nbsp;&amp;nbsp; totalPrice1 = (Row[1]) &amp;nbsp;&amp;nbsp;&amp;nbsp; for Row in FirstCursor: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Row[0] == "Example 1": &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; totalPrice1 += (Row[1]) del Row del FirstCursor&amp;nbsp; SecondCursor = arcpy.da.SearchCursor(fcName,Fields) for Row in SecondCursor: &amp;nbsp;&amp;nbsp;&amp;nbsp; totalPrice2 = (Row[1]) # Something needs to be changed here to get the first value correct &amp;nbsp;&amp;nbsp;&amp;nbsp; for Row in SecondCursor: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Row[0] == "Example 2": &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; totalPrice2 += (Row[1]) del Row del SecondCursor&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Nov 2013 02:56:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculation-error-using-cursors-second-cursor-uses/m-p/139655#M10897</guid>
      <dc:creator>jasonfargo</dc:creator>
      <dc:date>2013-11-20T02:56:10Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation error using cursors, second cursor uses first value of first cursor</title>
      <link>https://community.esri.com/t5/python-questions/calculation-error-using-cursors-second-cursor-uses/m-p/139656#M10898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Can't you just do something like this?:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Fields = ['Field1','Dollar Value'] totalPrice1 = 0.0 totalPrice2 = 0.0 TheOnlyCursorNeeded = arcpy.da.SearchCursor(fcName,Fields) for Row in TheOnlyCursorNeeded: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Row[0] == "Example 1": &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; totalPrice1 += (Row[1]) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif Row[0] == "Example 2": &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; totalPrice2 += (Row[1])&amp;nbsp; del Row del TheOnlyCursorNeeded&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Nov 2013 03:18:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculation-error-using-cursors-second-cursor-uses/m-p/139656#M10898</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-11-20T03:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation error using cursors, second cursor uses first value of first cursor</title>
      <link>https://community.esri.com/t5/python-questions/calculation-error-using-cursors-second-cursor-uses/m-p/139657#M10899</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Can't you just do something like this?:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Fields = ['Field1','Dollar Value']
totalPrice1 = 0.0
totalPrice2 = 0.0
TheOnlyCursorNeeded = arcpy.da.SearchCursor(fcName,Fields)
for Row in TheOnlyCursorNeeded:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if Row[0] == "Example 1":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; totalPrice1 += (Row[1])
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif Row[0] == "Example 2":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; totalPrice2 += (Row[1])

del Row
del TheOnlyCursorNeeded
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, but then totalPrice2 always has an incorrect value when I do the math manually.&amp;nbsp; It uses the first value from Example1 then continues to add Example2 values to it.&amp;nbsp; Example1 values end up correct, but the Example2 values always seem to get that first record wrong which makes the final value incorrect.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:43:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculation-error-using-cursors-second-cursor-uses/m-p/139657#M10899</guid>
      <dc:creator>jasonfargo</dc:creator>
      <dc:date>2021-12-11T07:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation error using cursors, second cursor uses first value of first cursor</title>
      <link>https://community.esri.com/t5/python-questions/calculation-error-using-cursors-second-cursor-uses/m-p/139658#M10900</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That doesn't make sense - can you post some of your data?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have not tested further, but the only thing I can think of at this point is possibly an indention error with this block, corrected below (this time I am using tabs):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for Row in TheOnlyCursorNeeded:
 if Row[0] == "Example 1":
&amp;nbsp; totalPrice1 += (Row[1])
 elif Row[0] == "Example 2":
&amp;nbsp; totalPrice2 += (Row[1])
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:43:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculation-error-using-cursors-second-cursor-uses/m-p/139658#M10900</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-11T07:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation error using cursors, second cursor uses first value of first cursor</title>
      <link>https://community.esri.com/t5/python-questions/calculation-error-using-cursors-second-cursor-uses/m-p/139659#M10901</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;That doesn't make sense - can you post some of your data?&lt;BR /&gt;&lt;BR /&gt;I have not tested further, but the only thing I can think of at this point is possibly an indention error with this block, corrected below (this time I am using tabs):&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
for Row in TheOnlyCursorNeeded:
 if Row[0] == "Example 1":
&amp;nbsp; totalPrice1 += (Row[1])
 elif Row[0] == "Example 2":
&amp;nbsp; totalPrice2 += (Row[1])
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Your suggestion worked perfectly, It was a selection error on my part while troubleshooting.&amp;nbsp; thank you&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:43:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/calculation-error-using-cursors-second-cursor-uses/m-p/139659#M10901</guid>
      <dc:creator>jasonfargo</dc:creator>
      <dc:date>2021-12-11T07:43:06Z</dc:date>
    </item>
  </channel>
</rss>

