4 Replies Latest reply: Jan 17, 2014 2:24 AM by Jerry Lau RSS

    defining variable in script

    Jerry Lau

      i want to include a set analysis expression in script:

       

      variable name:

      condition1

       

      definition:

      year1={$(=Year(Max(date1))-1)},month1={$(=Month(Max(date1)))}

      // where year1,month1 and date1 are attributes from my data source

       

      expression:

      Sum({<$(condition1)>}amount1)

       

      this can be easily done by storing it through "Settings">"Variable Overview"

       

      but how can i manage the variable condition1 in "edit script"?

       

      it is quite confusing to me for when to apply dollar sign, using let or set, ... etc

       

      i have read blogs from Henric, but i still don't understand how to do it

      http://community.qlik.com/blogs/qlikviewdesignblog/2013/11/04/the-magic-of-variables

      http://community.qlik.com/blogs/qlikviewdesignblog/2013/11/18/dollar-expansions

       

      thank you

        • Re: defining variable in script
          Antoine Frangieh

          Set analysis doesn't work in script unfortunately. you'll have to develop a specific script that performs the logic of your set analysis.

           

          EDIT:
          SET command fixes the content of your variable.

          i.e. SET x = 1+2

          When interpreted by using dollar sign expansion $(x) will give 1 +2

           

          LET x = 1+ 2

          When interpreted $(x) will give 3

           

          Hope this helps

          • Re: defining variable in script
            Michiel van de Goor

            Why do you want to do this in your script?

             

            Your expression can be calculated in the front end. It will be dynamic too, displaying the current selection as well.

             

            If your goal is to always calculate for the max date you can add to your set analysis the following statements:

            Sum({<$(=Year(Max(date1))-1)},month1={$(=Month(Max(date1))), year = , mont =, >}amount1)


            The year = and month = statements eliminate the selections done on these dimensions in list boxes.

            • Re: defining variable in script

              Hello Jerry,

              Hope are doing well.

               

              Please find below the differences:

              1. SET: is used in the script to store value (text/numeric) in a variable
              2. LET: is used in the script to store a value having some Qlikview function in a variable

              e.g.

              • Just type below two commands in your script editor

              SET vName1=Upper(Jerry);

              LET vName2= Upper(Jerry);

              • Debug/Load the script
              • Check the values stored under these two variables
              • Even while defining them in the script, you can see the difference in color, Suggestion starts appearing

                 3.  Dollar sign expansion (DSE): is used to resolve/ refer a variable which contains numeric value or uses Qlikview functions. It can not be used to resolve a variable which contains text value e.g. vName1 in above case. DSE is not desired if the variable contains some plain number, but its a good practice to use DSE.

              DSE should not be used to resolve variable which contains Text value, else it will output a null/ missing value.

              • Re: defining variable in script
                Jerry Lau

                thanks for your answers

                but i get the solution from an older post: Putting Dollar Expansion in Variable

                either

                1) using Replace() function (but that does not work for me, i don't know why)

                2) split the string after any dollar sign and concatenate segments manually