Score:-1

Sum the grouped results in the template

ng flag

I have an aggregated view result grouped by taxonomy terms and shown like the following.

TaxonomyTerm1
1
1
TaxonomyTerm2
1
TaxonomyTerm3
1
1
1

I want the result to be added and shown like the following.

TaxonomyTerm1
2
TaxonomyTerm2
1
TaxonomyTerm3
3

I tried to calculate the result in views-view-fields--reports.html.twig file with the following code.

{% set total = 0 %}
{% for field in fields -%}
  {% set total = total + 1 %}
{%- endfor %}
{{ total }}

Instead of the expected result, I get the original values again.

Score:0
ng flag

I have solved the problem with using View Aggregator Plus module. These are the settings I used on Views > View Aggregator Plus Module > Style > Settings.

  • For the taxonomy column
    1. In Apply group functions for the taxonomy column the result must be grouped by, select the Group and compress option
    2. In the Render column section, select the taxonomy column you want to shown as label
  • For the total number column
    1. In Apply column function, select Count (having regexp) *
    2. In the Render column section, select the title, for example as a field, because any field that repeats will be counted as total number with these options

To make it clearer, these are my fields.

  • TaxonomyColumn (which is being grouped by)
  • Title (the titles for the nodes with the taxonomy column)

Most importantly, make sure the default aggregation is disabled. It is by default, since the View Aggregator Plus module provides many aggregation options.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.