0

I am using the default view Taxonomy term.

I added a "number" field to my article content type.

I would like to obtain the average of the fields of the nodes listed by term of taxonomy.

For example, I have two nodes, which have as fields numbers: 2 and 4, and whose term is common taxonomy: A.

I would like in the view of the term taxonomy A, get the average of the fields "number" of these nodes, namely 3.

I tried views aggregation, add two fields: a field of type "Content: title", with aggregation: Group together, and a field of type "AVG (Content: Note)", with aggregation: "Average".

But it does not work.

I tried to add different relationships, but without success.

Someone would know the right configuration of views to do that? Thank you

1 Answer 1

0

I'm not aware of a configuration that can do that out of the box on the Content type Views. But if it must be that exact Taxonomy Terms Views you can do it with the help of an additional module (check out Views Calc and Views Aggregator Plus).

But if you only want the result, to show the Average number on Term pages, then you can create a different View, of type Taxonomy term and display it as a Block on term pages. This type will work without additional modules.

  1. Create Term Views type
  2. Filter to your Vocabulary, filter Note field to be Not empty
  3. Add the Taxonomy Name field, just to test, you'll see terms listed in separate Views rows
  4. Add the Relationship to all content using the field Content using Note, (Relate each Content with a Note set to the term.) You can require this Relationship
  5. DO NOT add any Sort criteria, sorting often messes up Aggregation
  6. Add the Note Field, it will show separate Nodes' Note numbers in separate Views rows
  7. Turn ON Aggregation
  8. Edit the Note Field Aggregation and set it to Average, Group column Value

    You should now again only see individual terms in rows, and the Note will show the average number calculated

  9. Check the Note field Formatter, the Default might round the numbers not to show decimal places, Unformatted might show more
  10. If this is all working the last thing to do is to add a Contextual filter to filter according to the term page you're viewing: Add the Contextual for the field relating to your relevant Taxonomy terms and configure it:
    When the filter value is NOT available
    Provide default value
    Taxonomy term ID from URL
    Load default filter from term page
    When the filter value IS available or a default is provided
    Specify validation criteria
    Taxonomy term ID

    Now you can enter a term ID into Preview field and you'll see what the block will display on that term's taxonomy page.

Place the block in a region, configure the block, limit the Visibility to term pages etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.