I'm working with QGIS 3.16 Hannover.

I've got a rule-styled polygon layer cuadric_cabañ. Rules are:

overlay_intersects(layer:='habitat_caba',filter:=(CODIIGE=210 OR CODIIGE=320))

Both shapefiles are available in this link

Both rules have their own label RABILARGA and COGUJADA(see image) and, using the corresponding button, I've obtained their simple statistics:

enter image description here

In the print composer I've placed a legend that I want it to read

RABILARGA (n = 294)
COGUJADA (n = 297)

Is it possible that those figures (294 and 297) could be invoked directly for the statistics of the rule?

Alternatively, I have built a code that works in an independent text box but, surprisingly, not within the legend description for that class:

'n = ' || aggregate(layer:= 'cuadric_cabañ',
filter:=overlay_intersects(layer:= 'habitat_caba', filter:=CODIIGE=330))

2 Answers 2


If you are looking for a way to display it on your main maps legend, right click your layer in the layer-panel and select "show feature count":

enter image description here


In the legend item properties, simply uncheck Auto update and then click Show feature count for each class of vector layer:

Screenshots: layer p1 is styled in yellor or orange depending on how many intersecting polygons from the red layer (p2) there are: enter image description here

enter image description here

You can add further text by clicking Edit selected item properties (pen icon) and adding text. However, the format with the square brackets is fixed, you can't change it (at least not here): enter image description here

  • Yes, that's the answer: Show feature count for each class of vector layer. However, can this count text style be edited? E.g. to show [n = 5] instead of simply [5]
    – jpinilla
    Nov 20, 2021 at 12:19
  • Updated my answer
    – Babel
    Nov 20, 2021 at 12: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.