<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Variables in the Script in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Variables-in-the-Script/m-p/1079268#M359846</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So I guess what can I replace vVar1 in order for vVar4 to work? I tried &lt;STRONG&gt;SET vVar1 = 'ABC';&lt;/STRONG&gt;, but that did not work as well. Is the only way is to do this by &lt;STRONG&gt;LET vVar2 = Chr(39) &amp;amp; 'ABC' &amp;amp; Chr(39);&lt;/STRONG&gt;?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 21 Feb 2016 21:12:33 GMT</pubDate>
    <dc:creator>sunny_talwar</dc:creator>
    <dc:date>2016-02-21T21:12:33Z</dc:date>
    <item>
      <title>Variables in the Script</title>
      <link>https://community.qlik.com/t5/QlikView/Variables-in-the-Script/m-p/1079266#M359844</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Team -&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am going to confess that I am not an expert on LET and SET statements and find it amazingly difficult to understand what will work and what won't. I know the basic difference between the two that LET evaluates, whereas SET will just assign a value to a variable. But when I have to do some letting or setting, I always end up with a trial and error method of getting it right rather then knowing what is right.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question today isn't related to LET and SET specifically, but I have a feeling that we are going to drive this discussion toward the use of LET vs. SET. Here is the script I am working with:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="sql" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14560871369882910" jivemacro_uid="_14560871369882910"&gt;
&lt;P&gt;//Works&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;LET vVar2 = Chr(39) &amp;amp; 'ABC' &amp;amp; Chr(39);&lt;/P&gt;
&lt;P&gt;LET vVar3 = Chr(39) &amp;amp; If($(vVar2) = 'ABC', 'DEF', '') &amp;amp; Chr(39);&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;// Doesn't Work&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;LET vVar1 = 'ABC';&lt;/P&gt;
&lt;P&gt;LET vVar4 = Chr(39) &amp;amp; If(Chr(39) &amp;amp; $(vVar1) &amp;amp; Chr(39) = 'ABC', 'DEF', '') &amp;amp; Chr(39);&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For sum reason, vVar3 seems to work as I would expect, but vVar4 won't. Is there a reason why one would work and the other one won't?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your expert advice on the topic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Sunny&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Sunny T Added the sample application&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Feb 2016 20:35:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Variables-in-the-Script/m-p/1079266#M359844</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2016-02-21T20:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: Variables in the Script</title>
      <link>https://community.qlik.com/t5/QlikView/Variables-in-the-Script/m-p/1079267#M359845</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Having issues with SET / LET / variable expansions etc. it's helpful to run the script in debug mode.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The line with variable vVar4 will expand to&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LET vVar4 = Chr(39) &amp;amp; If(Chr(39) &amp;amp; ABC &amp;amp; Chr(39) = 'ABC', 'DEF', '') &amp;amp; Chr(39)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you already pinpoint the cause of the issue? Examine the replaced variable: Is it a valid literal string or something else?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Feb 2016 20:50:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Variables-in-the-Script/m-p/1079267#M359845</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2016-02-21T20:50:57Z</dc:date>
    </item>
    <item>
      <title>Re: Variables in the Script</title>
      <link>https://community.qlik.com/t5/QlikView/Variables-in-the-Script/m-p/1079268#M359846</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So I guess what can I replace vVar1 in order for vVar4 to work? I tried &lt;STRONG&gt;SET vVar1 = 'ABC';&lt;/STRONG&gt;, but that did not work as well. Is the only way is to do this by &lt;STRONG&gt;LET vVar2 = Chr(39) &amp;amp; 'ABC' &amp;amp; Chr(39);&lt;/STRONG&gt;?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Feb 2016 21:12:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Variables-in-the-Script/m-p/1079268#M359846</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2016-02-21T21:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: Variables in the Script</title>
      <link>https://community.qlik.com/t5/QlikView/Variables-in-the-Script/m-p/1079269#M359847</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree this is often confusing and can create a lot of headaches....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you look at the critical part in line 9:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;Chr(39) &amp;amp; $(vVar1) &amp;amp; Chr(39)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $-sign expansion is always done &lt;SPAN style="text-decoration: underline;"&gt;before&lt;/SPAN&gt; QlikView try to interpret &lt;SPAN style="text-decoration: underline;"&gt;anything else&lt;/SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; So this will become:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Chr(39) &amp;amp; ABC &amp;amp; Chr(39)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px; line-height: 1.5em;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; The QlikView tries to interpret and would then think that &lt;STRONG&gt;ABC&lt;/STRONG&gt; is a variable.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; It can't find a variable named ABC so it evaluates to an empty string... &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; And then QlikView will finally end up with '' as the result.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you change line 09 to this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;LET vVar4 = Chr(39) &amp;amp; If( vVar1 = &lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;'ABC'&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;, &lt;/SPAN&gt;&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;'DEF'&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;, &lt;/SPAN&gt;&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;''&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;) &amp;amp; Chr(39);&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 9pt !important; font-style: inherit; background-color: inherit; font-weight: inherit;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 9pt !important; font-style: inherit; background-color: inherit; font-weight: inherit;"&gt;&lt;STRONG&gt;This will work as you intend&lt;/STRONG&gt;. Why would we want to make it more complicated by not accessing the variable value directly? Using $-sign expansion should only be used when it is absolutely necessary as it often complicates things.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 9pt !important; font-style: inherit; background-color: inherit; font-weight: inherit;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 9pt !important; font-style: inherit; background-color: inherit; font-weight: inherit;"&gt;So my advice is to use direct variable references without $-sign expansion whenever you can and only use $-sign expansion when you have to. It is necessary to use $-sign expansion sometimes because QlikView can't understand that we want the contents of a variable to be used inside for instance a string or a Set Expression. But you always have to remember that $-sign expansion is performed first before QlikView even tries to understand what the text in the load script or an expression in the UI really means. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 9pt !important; font-style: inherit; background-color: inherit; font-weight: inherit;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 9pt !important; font-style: inherit; background-color: inherit; font-weight: inherit;"&gt;$-sign expansion works as if we really did the substitution ourselves and only after that the normal QlikView interpretation will begin.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 9pt !important; font-style: inherit; background-color: inherit; font-weight: inherit;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 9pt !important; font-style: inherit; background-color: inherit; font-weight: inherit;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: black; font-size: 9pt !important; font-style: inherit; background-color: inherit; font-weight: inherit;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Feb 2016 21:19:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Variables-in-the-Script/m-p/1079269#M359847</guid>
      <dc:creator>petter</dc:creator>
      <dc:date>2016-02-21T21:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: Variables in the Script</title>
      <link>https://community.qlik.com/t5/QlikView/Variables-in-the-Script/m-p/1079270#M359848</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;
&lt;P&gt;&lt;SPAN style="color: black; font-size: 9pt; font-style: inherit; font-weight: inherit; line-height: 1.5em; background-color: inherit;"&gt; Using $-sign expansion should only be used when it is absolutely necessary as it often complicates things.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;To your point, I was not even aware that we can use a variable without a dollar sign expansion in the script. &lt;/SPAN&gt;I have learnt something new today because before today I thought that variable in the script would look grey italicized. But that seems not to be true:&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;IMG alt="Capture.PNG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/115381_Capture.PNG" /&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;In the above example, I see that vVar1 (on line 27) looks like a field, but it actually is a variable.&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;Thanks for sharing the logic and explaining it in detail.&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;Best,&lt;/P&gt;&lt;P style="font-size: 13.3333px;"&gt;Sunny&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Feb 2016 21:35:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Variables-in-the-Script/m-p/1079270#M359848</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2016-02-21T21:35:38Z</dc:date>
    </item>
  </channel>
</rss>

