I have multiple points with locations on a map and I want to calculate the exact number of points for a selected area. I created a polygon and with Numbers of points on the polygon I created a new layer which in the attribute table contains the number of points in the polygon.

attribute table

I want to export the map as an image. I used Print Layout but I don't know how to add the number of points from the attribute table to the legend.

enter image description here


3 Answers 3


You can use the following expression if there is one polygon.

@layer_name  +  ' (' + 
  to_string(array_get(array_agg( "NUMPOINTS" ), 0))
+ ')'

enter image description here


You may just double click on the legend text (in the legend properties panel, you need to deselect the auto-update option) and edit the legend text (you could just type the value or use an expression to retrieve it from the attribute table)

If you want to use an expression one possible example is

display_expression( 'display_expression( 'numpointsofHR', get_feature_by_id( 'numpointsofHR', 1 )

For this to work you need to set the display name in the layer properties to your NUMPOINTS field


The simplest way of doing this, is to go back to the map window, right click the layer and select "Show feature count". This will give you the feature count in the legend both in the map window and in your layout.

Pop up menu for the layer,

  • 2
    It will display "1" as feature count (there are only one polygon in the numpointsofHR layer), not the expected 76690 value from the attribute table of numpointsofHR....
    – J.R
    Jan 21 at 10:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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