Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Simpler way to call variables

Hello,

Inside a chart with one dimension (Brand), I'm calling a variable in an expression like this

=if(Brand='Mercedes',vMercedes,if(Brand='BMW',vBMW,if(Brand='Peugeot',vPeugeot))) // and so on

This works but is not efficient. I have to write an if statement for every brand and I have to change this if more brands come in.

I tried many different approaches like:

=$('v'&Brand)

or just

='v'&Brand

and many other things that fail calling the variable.

Is there a simple way to do it without all the if's?

Thank you so much,

Nuno

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Nuno,

the idea is nice, but I believe you get a hard time doing this with variable name construction / dollar sign expansion because of the way QV evaluates the expression / dollar sign expansion variables.

I think you won't get QV to return you the current dimension value, then let you combine the dimension value with some other character to form a variable name, then re-evaluates this as variable.

In princinple, I would do your conditional logic like

=pick( match( Brand, 'Mercedes', 'BMW','Peugeot'), vMercedes, vBMW, vPeugeot)

You can create a variable that builds this dynamically, then try to call the variable in your expression, like

='pick(match(Brand,'&chr(39)&concat({1} Brand,chr(39)&','&chr(39))&chr(39)&

') ,v'&concat({1} Brand,' ,v') &')'

View solution in original post

3 Replies
swuehl
MVP
MVP

Nuno,

the idea is nice, but I believe you get a hard time doing this with variable name construction / dollar sign expansion because of the way QV evaluates the expression / dollar sign expansion variables.

I think you won't get QV to return you the current dimension value, then let you combine the dimension value with some other character to form a variable name, then re-evaluates this as variable.

In princinple, I would do your conditional logic like

=pick( match( Brand, 'Mercedes', 'BMW','Peugeot'), vMercedes, vBMW, vPeugeot)

You can create a variable that builds this dynamically, then try to call the variable in your expression, like

='pick(match(Brand,'&chr(39)&concat({1} Brand,chr(39)&','&chr(39))&chr(39)&

') ,v'&concat({1} Brand,' ,v') &')'

Not applicable
Author

Did you tried as below:

Create a variable (ex:vBrand) and assign below expression to that variable.

vBrand='v'&Brand

now, you can use this variable as $(vBrand)

See the attachment.

swuehl
MVP
MVP

This only works if you select a Brand value, not when you need to use it in chart's expression.

I've adapted this file to show what I suggested above.