2

I've recently updated to QGIS 2.14, and have started using the custom variables feature implemented in 2.12. I was wondering whether it was possible to use the custom variable to select a field in the expression builder?

For example, I have a table containing data for three different time periods (AM, IP and PM). If I define a variable "TimePeriod", I'd like to be able to select a field in the expression builder for both labels and style in a way similar to

"@TimePeriod Count"

(where "AM Count", "IP Count" and "PM Count" are three fields in the table)

Is this possible? If so, what would the correct syntax be?

1 Answer 1

6

There was a function eval introduced in QGIS 2.14 that allows doing this. Basically it accepts a string that is evaluated like an expression itself.

eval( CONCAT( '"', @TimePeriod, ' ', 'Count' , '"' ) )
1
  • Perfect, this is exactly what I was after. Thanks very much! Apr 5, 2016 at 8:23

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.