From a layout in which I use two independent text labels, as you can see in the screenshot:

enter image description here

This text labels use the following expressions that make a calculation on two different layers:


Is there any option or way to format the style of these two text labels, comparing both values and colouring it in green the maximum one and in red the minimum one?

enter image description here

  • To clarify @JGH 's approach, the comparison between the two layer values should be made directly, rather than comparing content in the text boxes. There is no way at present for the expression builder to extract the contents of a text box item in a print layout
    – she_weeds
    Feb 29 at 15:43

1 Answer 1


Use the data defined override for the label text color. Just use an expression to compare your two value and return green or red as needed :

    WHEN (format_number(aggregate('DELIC_2020','sum',"PROCEDIMENT"),1)) > (format_number(aggregate('DELIC_2021','sum',"PROCEDIMENT"),1))
        THEN 'green'
    ELSE 'red'

This expression will return green (using color name, you may also use rgb or hex code, just make sure to return it as string) when DELIC_2020 value is greater than the DELIC_2021 value and red when it's not. Adapt the expression to get the right color to the right label.

enter image description here

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.