Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Defining a local variable in a chart expression

Is it possible to define a local variable within a chart expression? I need to manipulate a calculated value multiple times in the same expression and it would make my expression much cleaner and easier to manage if I could just refer to a variable instead of copying the calculation every time I need the value.

4 Replies
Not applicable
Author

Hello,

When you create the variable don't have an =.  Just the expression.   Then to reference it in the expression you would do something like:    $(vVariableName)

Regards,
Jeff

Not applicable
Author

Hey Jeff, sorry I haven't gotten back to this in a while. I've never worked with variables before, so I'm not even sure where to begin with that. Do you create variables in the load script? And can you give me an example of what a simple variable definition looks like and how it differs from what you suggested above?

Not applicable
Author

Are you planning to use the variable in the load script? Or would you be using it in your charts/tables?

If you are using in the load script an example would be

LET vVariable = 'sum expression

referenced with $(vVariable)

If not in the load script:

Settings --> Variable Overview --> Add

Name your variable then click on it, and down in the definition box, write your expression.

Regards,
Jeff

Not applicable
Author

Ok, I think that makes sense. I guess my question was whether it was possible to define a variable within a chart expression (useful and less cluttered than other options if you use the same piece of code multiple times in a single expression but nowhere else in qview file). I suppose defining it in Variable Overview is an ok substitute. Thanks for your help!