<p>Can you not do:    </p>

<pre><code>{% set total = 0 %}

{% for charge in charges %}
    {% set total = total + charge.amount %}
{% endfor %}

{{ total|number_format(2, '.', ',') }}
</code></pre>

<p>?</p>

CC BY-SA 3.0
2017-05-11T16:03:10.057Z
OK - it did but need to `{% set total = total + charge.amount %}` for it to work. If you want to edit the answer, I'll mark it off.
Steven Grant
CC BY-SA 3.0
2017-05-11T15:28:45.797Z
2017-05-11T16:23:25.980Z
2017-05-11T16:23:25.980Z
John
<p>I'm using Charge to collect donations toward individual projects for a charity.</p>

<p>On the frontend, I want to display how much has been raised for an individual project.</p>

<p>To get a list of charges for a project, I'm doing</p>

<pre><code>{% set charges = craft.charge.charges({  
      search : { query : 'projectDonateTo:' ~ entry.id }}
   )%}

{% for charge in charges %}
    {{ charge.amount }}
{% endfor %}
</code></pre>

<p>which obviously loops through all charges but I can't fathom how to total these together.</p>

<p>Any ideas?</p>

<templating><plugin-charge>
Collecting total charge value where custom field is X
# Collecting total charge value where custom field is X

(Asked by: username_0 on 2017-05-11)

I'm using Charge to collect donations toward individual projects for a charity.
On the frontend, I want to display how much has been raised for an individual project.
To get a list of charges for a project, I'm doing
{% set charges = craft.charge.charges({  
      search : { query : 'projectDonateTo:' ~ entry.id }}
   )%}

{% for charge in charges %}
    {{ charge.amount }}
{% endfor %}

which obviously loops through all charges but I can't fathom how to total these together.
Any ideas?

**Tags:** templating, plugin-charge


---

## 1 answers

### Answer by username_1 on 2017-05-11. Score: 1 | Accepted answer

Can you not do:    
{% set total = 0 %}

{% for charge in charges %}
    {% set total = total + charge.amount %}
{% endfor %}

{{ total|number_format(2, '.', ',') }}

?

> **Comments:**
> **username_0**: OK - it did but need to `{% set total = total + charge.amount %}` for it to work. If you want to edit the answer, I'll mark it off.  

---

