Answers.Body: <p>Something like this should work:</p>
  
  <pre><code>{% set reviews = craft.entries.section('reviews').relatedto(entry) %}
  {% set value = 0 %}
  {% set condition = 0 %}
  {% set reception = 0 %}
  {% set count = 0 %}
  {% for review in reviews %}
      {% set value = value + review.value %}
      {% set condition = condition + review.condition %}
      {% set reception = reception + review.reception %}
      {% set count = loop.index %}
  {% endfor %}
  {% set averageValue = (value / count)|round(1, 'floor') %}
  {% set averageCondition = (condition / count)|round(1, 'floor') %}
  {% set averageReception = (reception / count)|round(1, 'floor') %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-12T10:29:06.133Z
Answers.Text: Hey Douglas, much appreciated, that works like a charm!
Answers.UserDisplayName: patrick C
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-12T06:54:00.393Z
Answers.LastActivityDate: 2015-04-12T07:01:46.490Z
Answers.LastEditDate: 2015-04-12T07:01:46.490Z
Answers.UserDisplayName: Douglas McDonald
Body: <p>I've setup a section for reviews with several fields as numbers for a rating 0-5, I'm trying to figure out how to get the total of all reviews and sum of all reviews to provide a single average for an entry the reviews relate to.</p>
  
  <p>What's the best approach to this.</p>
  
  <p>Example of my fields:</p>
  
  <p>Value
  Condition
  Reception
  etc</p>
  
  <p>all graded 0-5 (number fields).</p>
  
  <p>So how to go through the foreach and get the sum of all fields from all reviews then divide by total reviews for the related entry to get the average for each field.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-11T21:54:16.650Z
Comments.Text: Are you looking to get the average for a single entry or an overall average across every entry in you reviews section?
Comments.UserDisplayName: Aaron Berkowitz
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-12T10:30:46.773Z
Comments.Text: Hi Aaron, Douglas' code sample works, that will give me the average across each facet of a review, for the overall I will be able to define my own formula with weighting applied to each in order to calculate the total score out of 100 (as some facets have a lower importance to the overall score).
Comments.UserDisplayName: patrick C
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-04-12T14:09:54.800Z
Comments.Text: Great! Be sure to mark his answer as correct!
Comments.UserDisplayName: Aaron Berkowitz
Tags: <forloop>
Title: calculating average ratings from a series of review fields
ThreadText: # calculating average ratings from a series of review fields
  
  (Asked by: username_0 on 2015-04-11)
  
  I've setup a section for reviews with several fields as numbers for a rating 0-5, I'm trying to figure out how to get the total of all reviews and sum of all reviews to provide a single average for an entry the reviews relate to.
  
  What's the best approach to this.
  
  Example of my fields:
  
  Value
  Condition
  Reception
  etc
  
  all graded 0-5 (number fields).
  
  So how to go through the foreach and get the sum of all fields from all reviews then divide by total reviews for the related entry to get the average for each field.
  
  **Tags:** forloop
  
  > **Comments:**
  > **username_1**: Are you looking to get the average for a single entry or an overall average across every entry in you reviews section?  
  > **username_0**: Hi username_1, username_2' code sample works, that will give me the average across each facet of a review, for the overall I will be able to define my own formula with weighting applied to each in order to calculate the total score out of 100 (as some facets have a lower importance to the overall score).  
  > **username_1**: Great! Be sure to mark his answer as correct!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-04-12. Score: 5
  
  Something like this should work:
  
  ```
  {% set reviews = craft.entries.section('reviews').relatedto(entry) %}
  {% set value = 0 %}
  {% set condition = 0 %}
  {% set reception = 0 %}
  {% set count = 0 %}
  {% for review in reviews %}
      {% set value = value + review.value %}
      {% set condition = condition + review.condition %}
      {% set reception = reception + review.reception %}
      {% set count = loop.index %}
  {% endfor %}
  {% set averageValue = (value / count)|round(1, 'floor') %}
  {% set averageCondition = (condition / count)|round(1, 'floor') %}
  {% set averageReception = (reception / count)|round(1, 'floor') %}
  
  ```
  
  > **Comments:**
  > **username_0**: Hey username_2, much appreciated, that works like a charm!  
  
  ---
  
  