enter image description here

I have this attribute table. I locked my atlas generator by county. For each, I want the statistics of all the cities that are in each county. For example : If the page of SICARIO is showed I want :

  • Trapani
  • Palerme
  • Catane

Like so : enter image description here

For instance, I achieved showing just the statistics for one city for each county using this expression

"city_name" || ' : '|| round(( "people_ok" *100)/ "total_of_people") || '% of people are ok and'|| round(( "people_not_ok" *100)/ "total_of_people") || '% are not' , like that :

enter image description here

How can I do to tell QGIS to show ALL the cities that belong to SICARIO ?

While knowing that:

  • for SICARIO I have to display 3 cities
  • for RADEON 2 cities
  • for TUNEM 3 cities

It's unclear to me why when adding the attribute table, only the first line that matches is displayed.

  • If you use an atlas, you have a coverage layer. In a case like yours, it would make sense to have a coverage polygon layer for the counties and a separate (point or polygon) layer for the cities. Then you could identify the features (cities) within the current atlas feature. This is not the case, if I understand you correctly? You have only one layer and want to do this from there?
    – Babel
    Jan 8 at 16:07

1 Answer 1


If you have everything on one layer (as it seems to be the case), you should use aggregate functions and filter the aggregated city_names by conty_name to create an array with all cities in a county using array_agg() function. From this array, loop through each element (city) to get the respective attribute values for the fiels people_ok and people_not_ok.

Edit: I tested your sample project and had to make only small adjustments. Use a text layout element, not an attribute table layout element, to introduce this text, as you don't really need an attribute table element for this, you use it to create a text, containing different attribute values concatenated. HOwever, the expression also works if you intreroduce it in the attribute table layout element.

Use the expression below:

enter image description here

            array_agg (
            || ': ' ||
                get_feature('counties_cities','city_name', @element),
            || ' % of people are OK and ' ||
                get_feature('counties_cities','city_name', @element),
            || ' % are not'
        delimiter:= '\n' 
  • Thanks for answering @Babel ! Unfortunately it does not work for me cause I have to introduce the statistics with an attribute table as I have parent/children relation. It will not work with inserting a label as on my locked layer for my atlas does not have this information : "people_ok","people_not_ok"... Jan 9 at 8:36
  • Sorry, I'm not sure I understand your settings correctly. I looked at your attribute table and there you have this information. I can only answer based on what information you provide. Also, I don't understand what you mean by "locked" layer. You should probably share your project with sample/dummy data to see what you have. Otherwise, it is just guessing in the dark.
    – Babel
    Jan 9 at 8:41
  • you are right it is not easy to explain so I made a link with my project and my layers in it : we.tl/t-WGlj7hOKah. It will be more clear. Nevertheless, thanks for your help Jan 9 at 11:36
  • See updated answer - it works with your project/data.
    – Babel
    Jan 9 at 15:20
  • 1
    I do know how to thanks you @Babel ! It works so well !! Jan 9 at 16:20

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.