Answers.Body: <pre><code>{% amount = craft.entries
     .postDate(['and', '&gt;=' someDate, '&lt;=' ~ someOtherTime])
     .select('dollar')
     .relatedTo(category)
     .sum()
  %}
  </code></pre>
  
  <p>Loop through all years and sum the value </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-07-31T16:33:33.243Z
Answers.Text: This no longer works in Craft 4. sum() is expecting column data from a field. https://craftcms.com/docs/4.x/element-queries.html#executing-element-queries
Answers.UserDisplayName: Mosswalker
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-04T05:17:15.270Z
Answers.LastActivityDate: 2018-07-04T05:17:15.270Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I have a category group named <code>country</code>.   Each entry in <code>posts</code> is assigned to a <code>country</code> and a <code>dollar value</code>.  <code>dollar value</code> is a field, NOT a table cell.  </p>
  
  <p>On a country's given page (i.e., a category page), I want to sum the total value across all entries assigned to a given country by year (date posted) across all years for which there are entries.  </p>
  
  <p>Help...</p>
  
Tags: <templating>
Title: How can I sum value across entries assigned to a category for a given year across multiple years?
ThreadText: # How can I sum value across entries assigned to a category for a given year across multiple years?
  
  (Asked by: username_0 on 2018-07-03)
  
  I have a category group named `country`. Each entry in `posts` is assigned to a `country` and a `dollar value`. `dollar value` is a field, NOT a table cell.
  
  On a country's given page (i.e., a category page), I want to sum the total value across all entries assigned to a given country by year (date posted) across all years for which there are entries.
  
  Help...
  
  **Tags:** templating
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-07-04. Score: 1
  
  ```
  {% amount = craft.entries
     .postDate(['and', '>=' someDate, '<=' ~ someOtherTime])
     .select('dollar')
     .relatedTo(category)
     .sum()
  %}
  
  ```
  
  Loop through all years and sum the value
  
  > **Comments:**
  > **username_2**: This no longer works in Craft 4. sum() is expecting column data from a field. https://craftcms.com/docs/4.x/element-queries.html#executing-element-queries  
  
  ---
  
  