0

I'm using dynamic text within a text box in print composer in QGIS 3.12. Is it possible to assign and use variables within this to avoid repeating the same call several times?
I'm using [% attribute(@atlas_pagename, "Acres) %] to pull up the area of the current atlas feature, then later using the same number to calculate the percent of different features. Is it possible to assign the value of that call to a variable and use it later?

4

Yes. You can define for example a project variable like this :

my_area : attribute(@atlas_feature, 'Acres')

And use it in an expression with :

eval(@my_area)

NB : the expression must have a meaning in the context scope where it's used

3
  • Thank you! The project variable needs to be set on the variables tab of the project properties. And the expression should be entered without the single quotes, since the system supplies them. Works great once I figured that out. – Brian Fisher Feb 18 at 18:06
  • Alternatively, variables can be set for the layout on the layout properties panel. nyalldawson.net/2015/12/… for more info, it was written for QGIS 2, but still accurate for version 3.12 – Brian Fisher Feb 18 at 18:26
  • I removed the quote as you suggest – lejedi76 Feb 18 at 19:15

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.