0

I want to automate repetitive map creations. All these maps have a cities layer. In the layout view, I would like to have a table which shows me the sum of inhabitants.

To not always go back to the data window, build the sum of a selection and paste in the table cell, I was thinking that I can insert a fix table and use the expression builder to populate the cell content. But I don't have any idea to use it there.

I guess I have to

  1. Reference the layer 'cities'
  2. Select cities in a certain area by using one attribute (IF 'State' = Idaho)
  3. Build the sum of inhabitants (sum 'Population').

How can I build this expression in the layout view, so I would just have to change the 'State' value in the selection part and would get the sum, even if the data changes after setting up the layout?

1 Answer 1

1

This expression should give you what you need.

aggregate(
    'cities',
    'sum',
    "Population",
    filter:="State" = 'Idaho'
)

If you are using an Atlas to generate your maps you could adapt the expression to update automatically.

Something like:

filter:="State" = attribute(@atlas_feature, 'State')
1
  • Thanks, I accepted this as an answer. I tried aggregate before but did not apply the filter correctly. Your solution works as a charm. Atlas might be the next step :)
    – KoGIS
    Apr 18, 2023 at 7:32

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.