How to calculate average age members We are building a family community website with 600+ members.

One of the gimmicks will be some stats, like average age all members.

Is there a smart way to calculate this?
I don't think this will exactly answer your question, but I think it will help get you going in the right direction.

Within my application, I am grabbing entries that belong to the currently logged in user - finding the fields and then displaying an average distance.

If you'll notice I am setting a level': 2 in my parameters. That's because I am working with a structure and the first level is the "parent" entry that does not have any of the data I am attempting to average.

{# Get all of the entries entered by the user. #}
{% set entries = craft.entries({
    'section': 'mySection',
    'level': 2,
    'descendantOf': user.id
}) %}

{% if entries|length %}

    ...

    {% set value = 0 %}
    {% set count = 0 %}

    {% for entry in entires %}
        {% set value = value + entry.distance %}
        {% set count = loop.index %}
    {% endfor %}

    {% set averageDistance = (value / count)|round(1, 'floor') %}

    &lt;p&gt;Avg: {{ averageDistance }}&lt;/p&gt;

    ...

{% else %}
    {# Could not find any entries. #}
{% endif %}


So in a nutshell, you'll want to:


grab the entries from the appropriate section
find the field(s) you want to average ex: distance
do math
return the result


For you (this is a stab in the dark) you would want to get all users, get the value of the age field. Then loop over to get your count and divide that by the ages.

Hope this helps!