Qlik Community

QlikView Creating Analytics

Discussion Board for collaboration related to Creating Analytics for QlikView.

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

Tags (2)
1 Solution

Accepted Solutions
MVP
MVP

Re: Simpler way to call variables

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') &')'

3 Replies
MVP
MVP

Re: Simpler way to call variables

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

Re: Simpler way to call variables

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.

MVP
MVP

Re: Re: Simpler way to call variables

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.

Community Browser