There is a shapefile about facilities with columns "country"
and "annual production"
.
I am looking for an expression for a calc field to summarize total production for all countries.
For example: if a country has 5 facilities, I need to sum up each facility for the total production of this country.
Is there some expression to do that?
2 Answers 2
To calculate the sum per country, use this expression:
sum("production", group_by:="country")
Replace "production"
and "country"
with the field names you have.
-
1Thanks, it works, but "country" does not need to replace, it must stay like in Your example.GeoEth– GeoEth2022年12月15日 17:30:34 +00:00Commented Dec 15, 2022 at 17:30
-
2Yeah, as long as you use the same names, they can stay like this in the expression, of courseBabel– Babel2022年12月15日 17:49:02 +00:00Commented Dec 15, 2022 at 17:49
Try the Sum function:
sum("annual production","country")
I feel this should also work with the aggregate function:
aggregate('[[your layer name]]',sum,"annual production","country"=@parent)
-
3I think there are some errors in the second expression, take a look to the
aggregate
documentation. The correct expression is.aggregate('[[your layer name]]', 'sum', "annual production", "country"=attribute(@parent, 'country'))
Mayo– Mayo2022年12月15日 15:50:22 +00:00Commented Dec 15, 2022 at 15:50 -
To Hjall: no, doesn't work.GeoEth– GeoEth2022年12月15日 17:26:21 +00:00Commented Dec 15, 2022 at 17:26
Explore related questions
See similar questions with these tags.