I have a records table with site numbers and abundances of different species at that site (e.g. site 1 has 6 common bats and 13 pipistrellus bats).
I would like to sum total number (i.e. 6+13=19) at that site into another column within another table of a point shapefile locating the sites in some kind of expression used in the field calculator. Is this possible?
I have tried
aggregate( 'records', 'sum', "Abundance", "SiteNum")
but this has given me the same value (808) for every site in the new column of the point shapefile attribute table i.e. is ignoring the factor of site number.
1 Answer 1
So you want to sum
the "Abundance"
grouped by "SiteNum"
and place the results in another_table
with a common ID
?
The clue is in relation_aggregate()
. More info: https://docs.qgis.org/testing/en/docs/user_manual/working_with_vector/expression.html#aggregates-functions and in the expression-builder
First, you have to define a relation: Project> properties> relations.
- Set the relation with 'records' as child and 'another_layer' as parent.
Give the relation a name. This name you need in the
relation_aggregate()
relation_aggregate( relation:= 'name', aggregate:= 'sum', expression:= "Abundance" )
-
-
sometimes :-). But it is really hard to understand all the possibilities of the aggregate-functions...PieterB– PieterB2019年11月20日 12:52:13 +00:00Commented Nov 20, 2019 at 12:52
-
I edited my answer with more info about child and parentPieterB– PieterB2019年11月20日 13:06:17 +00:00Commented Nov 20, 2019 at 13:06
-
Which file-format is used to store the records? Which are the fieldproperties of 'SiteNum'? Are there unexpected spaces in the data? The same questions has to be asked for the other layer.PieterB– PieterB2019年11月20日 14:19:01 +00:00Commented Nov 20, 2019 at 14:19
Explore related questions
See similar questions with these tags.
aggregate
-expression of the field calculator?sum
part should read something like...'sum("Abundance",group_by:="SiteNum")'...
- but to be honest I have no idea what theaggregate
- expression should read then. Aggregate is like dark humor - not everyone gets it.sum(Abundance,SiteNum)
should work fine. So, what happens if we go withaggregate('layernamefromthefieldcalc','max','sum(Abundance,SiteNum)')
? It is important that you use the layername with which the abundance-layer is referenced under in the field calculator (point "map layer") - the simple'records'
wont work most likely.