3 Replies Latest reply: Oct 6, 2013 8:58 AM by Stefan Wühl RSS

    Simpler way to call variables

    Nuno Faustino



      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:


      or just


      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,


        • Re: Simpler way to call variables
          Stefan Wühl



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

          • Re: Simpler way to call variables

            Did you tried as below:


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


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

            See the attachment.