In the past, aggregating field values was reserved to databases, virtual layers, or dedicated plugins, but since QGIS 2.16, there is a way to compute aggregates directly in QGIS expressions. This means that we can compute sums, means, counts, minimum and maximum values and more!
Here’s a quick tutorial to get you started:
Load the airports from the QGIS sample dataset. We’ll use the elevation values in the ELEV field for the following examples:
The most straightforward expressions are those that only have one parameter: the name of the field that should be aggregated, for example:
We can also add a second parameter: a group-by field, for example, to group by the airport usage type, we use:
To top it all off, we can add a third parameter: a filter expression, for example, to show only military airports, we use:
Last but not least, all this aggregating goodness also works across layers! For example, here is the Alaska layer labeled with the airport layer feature count: