4

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?

enter image description here

Taras
35.8k5 gold badges77 silver badges152 bronze badges
asked Dec 15, 2022 at 14:21

2 Answers 2

10

To calculate the sum per country, use this expression:

sum("production", group_by:="country")

Replace "production" and "country" with the field names you have.

Taras
35.8k5 gold badges77 silver badges152 bronze badges
answered Dec 15, 2022 at 14:30
2
  • 1
    Thanks, it works, but "country" does not need to replace, it must stay like in Your example. Commented Dec 15, 2022 at 17:30
  • 2
    Yeah, as long as you use the same names, they can stay like this in the expression, of course Commented Dec 15, 2022 at 17:49
0

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)
answered Dec 15, 2022 at 14:42
2
  • 3
    I 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')) Commented Dec 15, 2022 at 15:50
  • To Hjall: no, doesn't work. Commented Dec 15, 2022 at 17:26

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.