3

I have a number of expressions in my legend of the following type to show proportions of a total and label them as a percentage of that total, eg:

19th century ([%round(aggregate(layer:='Dwelling_Other',aggregate:='count', expression:="Cons_Yr", filter:=("Locality" IN ('Archies Creek') AND "Cons_Yr" >= 1801 AND "Cons_Yr" <= 1900))/aggregate(layer:='Dwelling_Other',aggregate:='count', expression:="Cons_Yr", filter:=("Locality" IN ('Archies Creek') AND "Cons_Yr" >= 1801))*100)%]%)

These results and labels show correctly in the legend:

enter image description here

until clicking another item or opening another legend item, when they revert to displaying the expression itself instead: enter image description here

If I go back into a legend item and just backspace one or two characters, then it and all the other legend items revert back to showing the result. Is there a way to prevent this from happening?

1 Answer 1

2

I think it could be because of the ( followed by [. There is also a second % in the end of your formula. Expression should be surrounded by [% and %].

First delete the last %.

Then delete the parenthesis around your expression and add the parenthesis in the expression formula. You can use the formula below as an example :

19th century 
[% '(' || 
(
   round(aggregate(layer:='Dwelling_Other',aggregate:='count', expression:="Cons_Yr", filter:=("Locality" IN ('Archies Creek') AND "Cons_Yr" >= 1801 AND "Cons_Yr" <= 1900))
   /
   aggregate(layer:='Dwelling_Other',aggregate:='count', expression:="Cons_Yr", filter:=("Locality" IN ('Archies Creek') AND "Cons_Yr" >= 1801))*100)
) 
|| ')'%] 

NB : The || will work only if your number have parentesis around or if it is converted to text with to_string()

1
  • 1
    Thankyou Corentin. You are right, but those extra bits get appended by QGIS once I leave the expression window. I tried using the same expression in just a simple text label and there it is fine, so now I am inclined to think the issue is with using such an expression in the legend.
    – Funzo
    Mar 17 at 1:51

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.