Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-11T16:03:10.057Z
Answers.Text: 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.
Answers.UserDisplayName: Steven Grant
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-11T15:28:45.797Z
Answers.LastActivityDate: 2017-05-11T16:23:25.980Z
Answers.LastEditDate: 2017-05-11T16:23:25.980Z
Answers.UserDisplayName: John
Body: <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>
  
Tags: <templating><plugin-charge>
Title: Collecting total charge value where custom field is X
ThreadText: # 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.  
  
  ---
  
  