I am trying to use the expression editor on the legend item in the layout manager. My layer has the attributes of RU_NAME which is the geological unit and LITH_SUMM which is the description. Unfortunately the layer is huge and has colouring and categories set up by our local government department so I cannot just reclassify without loosing all of the colour and symbology styles.

Concat(@symbol_label,': ',"LITH_SUMM")

Above is the code I am using which should give me the combined name and description of the rock units. The preview has the correct output, but when I click OK it results in [%Concat(@symbol_label,': ',"LITH_SUMM")%]

Is there something I am doing incorrectly with the code for this expression?

EDIT: Please see the screenshot below: enter image description here

Our local government has released the shapefiles and styles for geological layers which are compliant to standards so I would not want to recategorize the layers based upon a new attribute. Doing this would overprint the colours and labels on a data set that has thousands of entries. The issue is that the legend only shows the symbols "Tp" instead of the description "Arkose sandstone with interbedded siltstone". The information is in the attribute table of the layer, I am just unsure how to get it to be displayed in the legend.

EDIT 2: See Below for additional information enter image description here

enter image description here I have attached an excerpt of the attribute table and the formatting style. The symbology has been set by the government to a standard colouring based upon RU_NAME. There are thousands of these categories. I have combined the required information in the attribute table asLegendText = Concat("MAP_SYMBOL","RU_NAME","LITH_SUMM") as an example of what I am trying to get to display in the legend text. I have tried to edit the layer style python and this guide:Using attribute data for legend labeling in QGIS? but I am definitely a novice at python and cannot get it to work.

1 Answer 1


You can't use entries from your attribute table for the legend: every entry in the legend stands for a whole layer with (often) many features, each with own attribute-values. Your expression looks like you want to add attribute-values to the legend, which would list all the attribute-values to the legend-item. However, the expression-editor for legend-items is not made for that, see the documentation:


You can use the expression editor here to add e.g. the number of features.

@MrXsquared: I'm not sure if the question is about atlas-generation, the question does not mention it. Form the posting it is not really clear what exactely you want to achieve - maybe you can be more clear or add a screenshot?


How is your layer styled? I guess you have one layer containing all the categories and you used the categorized symbol renderer as in the image below? In this case, in the second column you can enter manually the name that should appear on your legend in the print composer. Otherwise, please elaborate on your set-up, your data, to be able to understand what exactely you want to do and make an example how your outpus should look like. As stated, legend is not the place to show contents of your attribute table, since this contains individual values for each individual feature, but the legends shows categories, thus aggregated groups of features.

enter image description here

  • I have added a screenshot and further explanation.
    – LeadStar
    May 27, 2020 at 0:16
  • So each color is a separate shapefile? How should the output of the label look: can you make an expample? And can you post a screenshot of the attribute table with the fields you want to include? And Maybe as well one of the layer styling, to understand exactly your setup.
    – Babel
    May 27, 2020 at 6:59
  • Answer updated, see above
    – Babel
    May 27, 2020 at 7:22
  • Updated question. I realise I can rename manually, the issue is just the number of categories I would have to do that for would take too long
    – LeadStar
    May 27, 2020 at 21:36

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.