[ QGIS ] – “Aggregate” function

From the QGIS help:

aggregate function

Returns an aggregate value calculated using features from another layer.



[ ] marks optional components


layer a string, representing either a layer name or layer ID
aggregate a string corresponding to the aggregate to calculate. Valid options are:
count count_distinct count_missing min max sum mean median stdev stdevsample range minority majority q1: first quartile q3: third quartile iqr: inter quartile range min_length: minimum string length max_length: maximum string length concatenate: join strings with a concatenator collect: create an aggregated multipart geometry
expression sub expression or field name to aggregate
filter optional filter expression to limit the features used for calculating the aggregate. Fields and geometry are from the features on the joined layer. The source feature can be accessed with the variable @parent.
concatenator optional string to use to join values for ‘concatenate’ aggregate


  • aggregate(layer:=’rail_stations’,aggregate:=’sum’,expression:=”passengers”) → sum of all values from the passengers field in the rail_stations layer
  • aggregate(‘rail_stations’,’sum’, “passengers”/7) → calculates a daily average of “passengers” by dividing the “passengers” field by 7 before summing the values
  • aggregate(layer:=’rail_stations’,aggregate:=’sum’,expression:=”passengers”,filter:=”class”>3) → sums up all values from the “passengers” field from features where the “class” attribute is greater than 3 only
  • aggregate(layer:=’rail_stations’,aggregate:=’concatenate’, expression:=”name”, concatenator:=’,’) → comma separated list of the name field for all features in the rail_stations layer
  • aggregate(layer:=’countries’, aggregate:=’max’, expression:=”code”, filter:=intersects( $geometry, geometry(@parent) ) ) → The country code of an intersecting country on the layer ‘countries’

Useful idea on “Find Neighbor Polygons using Summary Aggregate Function in QGIS

for example:

layer:= ‘Zip_Codes’,
concatenator:=’, ‘,
filter:=touches($geometry, geometry(@parent))

layer:= ‘Ambiti_Amministrativi-Comuni’,
filter:=touches($geometry, geometry(@parent))

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: