<?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: Script SET variable vs. Variable Manager Issue in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Script-SET-variable-vs-Variable-Manager-Issue/m-p/478886#M691098</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Brian,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is what I perceive, when you assign variables in your script, they get assigned as part of script-execution process. In this process, QlikView does the Dollar-sign expansion - $() before the script statement is evaluated, i.e. before it gets assigned to the variable. This replaces the contents of $() function with its value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hence your expression changes from:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;SET eSGP = avg({1&amp;lt;school_id={$(vSchoolID)},subject_code = {$(=Only(subject_code))}&amp;gt;}sgp);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;to:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;avg({1&amp;lt;school_id={742},subject_code = {(internal error)}&amp;gt;}sgp)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Whereas, variables defined in the variable manager do not get assigned as part of script-execution, hence they remain - as is.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In case you still would like to assign the variable in the script, a workaround would be&lt;/P&gt;&lt;P&gt;to use a Two-Step approach, as given below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #339966;"&gt;//2 step approach: To prevent the $() evaluation:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #339966;"&gt;//Use ~ in place of $&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;SET eSGP_Intermediate = avg({1&amp;lt;school_id={~(vSchoolID)},subject_code = {~(=Only(subject_code))}&amp;gt;}sgp);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #339966;"&gt;//Replace '~' back to '$', before setting the variable&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;SET eSGP = "=Replace(eSGP_Intermediate, '~', '$')";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH,&lt;/P&gt;&lt;P&gt;KD&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 04 Sep 2013 08:27:57 GMT</pubDate>
    <dc:creator>kedar_dandekar</dc:creator>
    <dc:date>2013-09-04T08:27:57Z</dc:date>
    <item>
      <title>Script SET variable vs. Variable Manager Issue</title>
      <link>https://community.qlik.com/t5/QlikView/Script-SET-variable-vs-Variable-Manager-Issue/m-p/478884#M691096</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have the following variable definition:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13782415142739483" jivemacro_uid="_13782415142739483"&gt;
&lt;P&gt;SET eSGP = avg({1&amp;lt;school_id={$(vSchoolID)},subject_code = {$(=Only(subject_code))}&amp;gt;}sgp);&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;vSchoolID is set above in my script.&amp;nbsp; When I run the script with this definition and then check the variable manager after the load finishes, the value becomes:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13782414945218900" jivemacro_uid="_13782414945218900"&gt;
&lt;P&gt;avg({1&amp;lt;school_id={742},subject_code = {(internal error)}&amp;gt;}sgp)&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, if I do not set the variable at all in the script and simply create the variable in the Variable Manager with the exact same value definition I list above, the variable is correctly set after the load completes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suspect there is a timing issue here, but does anyone know why this happens?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Sep 2013 21:00:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-SET-variable-vs-Variable-Manager-Issue/m-p/478884#M691096</guid>
      <dc:creator>bdiamante</dc:creator>
      <dc:date>2013-09-03T21:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: Script SET variable vs. Variable Manager Issue</title>
      <link>https://community.qlik.com/t5/QlikView/Script-SET-variable-vs-Variable-Manager-Issue/m-p/478885#M691097</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Brian,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Without going into the "why" questions - set analysis syntax is not applicable to the script.&amp;nbsp; It works only in the front end expressions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Michael&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Sep 2013 23:54:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-SET-variable-vs-Variable-Manager-Issue/m-p/478885#M691097</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-09-03T23:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Script SET variable vs. Variable Manager Issue</title>
      <link>https://community.qlik.com/t5/QlikView/Script-SET-variable-vs-Variable-Manager-Issue/m-p/478886#M691098</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Brian,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is what I perceive, when you assign variables in your script, they get assigned as part of script-execution process. In this process, QlikView does the Dollar-sign expansion - $() before the script statement is evaluated, i.e. before it gets assigned to the variable. This replaces the contents of $() function with its value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hence your expression changes from:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;SET eSGP = avg({1&amp;lt;school_id={$(vSchoolID)},subject_code = {$(=Only(subject_code))}&amp;gt;}sgp);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;to:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;avg({1&amp;lt;school_id={742},subject_code = {(internal error)}&amp;gt;}sgp)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Whereas, variables defined in the variable manager do not get assigned as part of script-execution, hence they remain - as is.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In case you still would like to assign the variable in the script, a workaround would be&lt;/P&gt;&lt;P&gt;to use a Two-Step approach, as given below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #339966;"&gt;//2 step approach: To prevent the $() evaluation:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #339966;"&gt;//Use ~ in place of $&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;SET eSGP_Intermediate = avg({1&amp;lt;school_id={~(vSchoolID)},subject_code = {~(=Only(subject_code))}&amp;gt;}sgp);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #339966;"&gt;//Replace '~' back to '$', before setting the variable&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff;"&gt;SET eSGP = "=Replace(eSGP_Intermediate, '~', '$')";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH,&lt;/P&gt;&lt;P&gt;KD&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Sep 2013 08:27:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-SET-variable-vs-Variable-Manager-Issue/m-p/478886#M691098</guid>
      <dc:creator>kedar_dandekar</dc:creator>
      <dc:date>2013-09-04T08:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: Script SET variable vs. Variable Manager Issue</title>
      <link>https://community.qlik.com/t5/QlikView/Script-SET-variable-vs-Variable-Manager-Issue/m-p/478887#M691099</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Brian,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I assume you won't do this only for one expression, but for more...&lt;/P&gt;&lt;P&gt;In such a case I would recommend to have a file (Excel,CSV,etc) where to define the formulas for all your variables, read in script the file and aftwards, iteratively, transform each row of you formula definition in a variable and, within the same loop, populate it's content with the expression you need.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It will allow you to define very fast quite a lot of variables containing expressions.&lt;/P&gt;&lt;P&gt;And also to create variations in a snap through a simple copy-paste-modify process inside an XLS file !&lt;/P&gt;&lt;P&gt;Beyound all the above benefits, it should help you also with your issue...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sempre fi,&lt;/P&gt;&lt;P&gt;Cotiso&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Sep 2013 14:10:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Script-SET-variable-vs-Variable-Manager-Issue/m-p/478887#M691099</guid>
      <dc:creator>cotiso_hanganu</dc:creator>
      <dc:date>2013-09-04T14:10:04Z</dc:date>
    </item>
  </channel>
</rss>

