Sum up number fields in the loop I don't understand what's going on in my code logic because I'm getting unexpected output.

I'd like to sum up three number fields in entries loop for the given post date range. Output gets almost doubled as expected. What am I missing here?

{# Get this month's data #}
{% set thisMonthStatistic = orders.postDate('and', '&gt;= ' ~ firstDayOfMonth, '&lt;= ' ~ lastDayOfMonth) %}

{% if thisMonthStatistic|length %}
{# We must set variable "0" and pass it in for the looping's variable #}
{% set thisMonthEarning = 0 %}

  {# looping in "thisMonthStatistic" #}
  {% for statistic in thisMonthStatistic %}

    {% set aPrice = statistic.aPrice %}
    {% set bPrice = statistic.bPrice %}
    {% set cPrice = statistic.cPrice %}

    {% if aPrice &gt; 0 %}
      {% set aPrice = aPrice + thisMonthEarning %}
    {% endif %}

    {% if bPrice &gt; 0 %}
      {% set bPrice = bPrice + thisMonthEarning %}
    {% endif %}

    {% if cPrice &gt; 0 %}
      {% set cPrice = cPrice + thisMonthEarning %}
    {% endif %}

    {% set thisMonthEarning = aPrice + bPrice + cPrice %}

  {% endfor %}

{% else %}

  {% set thisMonthEarning = 0 %}

{% endif %}


{# Final variable output #}
{{ thisMonthEarning }}
Hmm... hard to tell because I can’t know what your expected result would be. But if I had to guess then you might be looking for just this:

{% if aPrice %}
    {% set thisMonthEarning = thisMonthEarning + aPrice %}
{% endif %}