I want to create a view and group the result like display only 1 record and along with it display the count of the similar records along with it. Can i do it in views with out writing any code. i.e. result should look like

Football (3)

Tennis (6)

Cricket (4)

3 Answers 3


You can create a Contextual Filter for whichever field you want to sort off of. If the filter value is not in the url it will display a list like you have above.

image of contextual filter using "number of records"

  • I don't want any sorting to be done. Just grouping and count to be displayed
    – Hacker
    Feb 9, 2012 at 5:39
  • 1
    Sorry, it is late. The "Display a summary" is what will do the grouping and counting. The "Sort order" will just be by 'most first'.
    – acouch
    Feb 9, 2012 at 5:48
  • Nice and simple :) I found this easiest to implement, but the summary itself is a bit inflexible.
    – Timmah
    Mar 13, 2020 at 9:22

My example is based on 1 Content Type and 1 field (City).

  1. FIELDS. Add 2 same fields in fields area you wanna group and show counter.
  2. FORMAT. Group by required field enter image description here
  3. PAGER. Set 0 in Pager area.
  4. ADVANCED. Enable aggregation in advanced settings enter image description here
  5. COUNT. Enabled 'count' for second field (which is not used to group) enter image description here
  6. Sorting. Set sorting as your group field.


This is how looks my view enter image description here


enter image description here


I need this feature and see this Q&A, I try it but not getting desire result, keeping on my search and I found Views Aggregator Plus . this is exactly I need and good solution for future guys that search for this feature.

As the Views and Views Calc modules rely on the database to perform aggregation, you only have limited options at your disposal. As the great Merlin himself said: "You can't aggregate a PHP expression in the database. :/ ". That's where Views Aggregator Plus comes in. In addition to what Views and Views Calc do, this module:

enumerates group members
produces tallies, i.e. textual histograms
aggregates on Views PHP code-snippet evalutations
can filter out result rows on regexp patterns
gives you sorting on Views' Math expressions
can process Webform submissions
lets you add your own custom aggregation functions

... and it puts summary statistics at the bottom of your aggregated table as well! Recap: what is aggregation again?

In the context of Views tables and this module, aggregation is the process of grouping and compressing result rows on the identical values of one column, while at the same time applying "summary" (aggregation) functions on other columns. For example, you can group the result set on a taxonomy term, so that all rows sharing the same value of the taxonomy column are represented as single rows, with aggregation functions like COUNT, ENUMERATE or SUM applied to the remaining columns. Example

Say the original View based on raw database results looks like below. Industry Company Name Turnover IT AquiB $ 25,000,000 Clothing Cenneton $ 99,000,000 Food Heiny $ 66,000,000 IT PreviousBest $ 5,000,000 Food McRonalds $500,000,000

Then with the grouping taking place on, say Industry, and aggregation functions TALLY, ENUMERATE and SUM applied on Industry, Company Name and Turnover respectively, the final result with a descending sort on the last column will display like below. Note that the module identified three groups. It also added a totals row, Views Calc style. Industry Companies Turnover Food (2) Heiny, McRonalds $566,000,000 Clothing (1) Cenneton $ 99,000,000 IT (2) AcquiB, PreviousBest $ 30,000,000 Totals 5 $695,000,000

But that's just the beginning. Remember, you can aggregate on Views PHP expressions, so the possibilities are endless! See the README for examples using PHP code snippets.

For the "totals" row you may use the module's Math expression column aggregation function and replacement tokens to calculate a field as, say, the product of two preceding fields.

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.