<?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 Using a variable in Set Analysis and script in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Using-a-variable-in-Set-Analysis-and-script/m-p/943966#M648301</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm having a problem using the same variable in the script and Set Analysis.&lt;/P&gt;&lt;P&gt;For example I want to load all the years, months and days from a predefined date QVD until the end of the current year. To do so I defined the following variable via Variable Overview (without outer quotes):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;vMaxYear: "=text(Date(today(), 'YYYY'))" &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To define it that way has the benefit of seeing the calculated value in an input box and especially it works in a Set Analysis like in a title string (without outer quotes): &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"=MinString({1&amp;lt;YEAR={"=$(vMaxYear)"}&amp;gt;} DAY&amp;amp;'.'&amp;amp;MONTH&amp;amp;'.'&amp;amp;YEAR)" &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yet it does not work in the script:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Date:&lt;/P&gt;&lt;P&gt;LOAD&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; YEAR, MONTH, DAY&lt;/P&gt;&lt;P&gt;FROM [..\shared\qvd\DATE.QVD](qvd)&lt;/P&gt;&lt;P&gt;WHERE YEAR&amp;lt;=$(vMaxYear);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Until now I tried many combinations of double/single quotes, equal signs and using/leaving dollar expansion but none of them worked in both application fields with only one definition of the variable. Yet I came to the result that leaving the = in the definition the script runs well but the Set Analysis does not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For now I prefer the definition with = since I can see the value in an input box but it just won't work in the script. Is there a solution for both using only a single variable? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 22 Oct 2015 08:21:59 GMT</pubDate>
    <dc:creator />
    <dc:date>2015-10-22T08:21:59Z</dc:date>
    <item>
      <title>Using a variable in Set Analysis and script</title>
      <link>https://community.qlik.com/t5/QlikView/Using-a-variable-in-Set-Analysis-and-script/m-p/943966#M648301</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm having a problem using the same variable in the script and Set Analysis.&lt;/P&gt;&lt;P&gt;For example I want to load all the years, months and days from a predefined date QVD until the end of the current year. To do so I defined the following variable via Variable Overview (without outer quotes):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;vMaxYear: "=text(Date(today(), 'YYYY'))" &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To define it that way has the benefit of seeing the calculated value in an input box and especially it works in a Set Analysis like in a title string (without outer quotes): &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"=MinString({1&amp;lt;YEAR={"=$(vMaxYear)"}&amp;gt;} DAY&amp;amp;'.'&amp;amp;MONTH&amp;amp;'.'&amp;amp;YEAR)" &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yet it does not work in the script:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Date:&lt;/P&gt;&lt;P&gt;LOAD&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; YEAR, MONTH, DAY&lt;/P&gt;&lt;P&gt;FROM [..\shared\qvd\DATE.QVD](qvd)&lt;/P&gt;&lt;P&gt;WHERE YEAR&amp;lt;=$(vMaxYear);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Until now I tried many combinations of double/single quotes, equal signs and using/leaving dollar expansion but none of them worked in both application fields with only one definition of the variable. Yet I came to the result that leaving the = in the definition the script runs well but the Set Analysis does not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For now I prefer the definition with = since I can see the value in an input box but it just won't work in the script. Is there a solution for both using only a single variable? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Oct 2015 08:21:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-a-variable-in-Set-Analysis-and-script/m-p/943966#M648301</guid>
      <dc:creator />
      <dc:date>2015-10-22T08:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using a variable in Set Analysis and script</title>
      <link>https://community.qlik.com/t5/QlikView/Using-a-variable-in-Set-Analysis-and-script/m-p/943967#M648302</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try creating vMaxYear as Year(Today()). You're now comparing numeric YEAR values with a text value.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Oct 2015 09:18:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-a-variable-in-Set-Analysis-and-script/m-p/943967#M648302</guid>
      <dc:creator>Gysbert_Wassenaar</dc:creator>
      <dc:date>2015-10-22T09:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Using a variable in Set Analysis and script</title>
      <link>https://community.qlik.com/t5/QlikView/Using-a-variable-in-Set-Analysis-and-script/m-p/943968#M648303</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, for me works with this:&lt;/P&gt;&lt;P&gt;variable: LET vMaxYear = Year(Today());&lt;/P&gt;&lt;P&gt;script: WHERE YEAR&amp;lt;=$(vMaxYear)&lt;/P&gt;&lt;P&gt;expression: Sum({&amp;lt;Year={$(vMaxYear)}&amp;gt;} Amount)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Oct 2015 09:22:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-a-variable-in-Set-Analysis-and-script/m-p/943968#M648303</guid>
      <dc:creator>rubenmarin</dc:creator>
      <dc:date>2015-10-22T09:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using a variable in Set Analysis and script</title>
      <link>https://community.qlik.com/t5/QlikView/Using-a-variable-in-Set-Analysis-and-script/m-p/943969#M648304</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, define your variable in the script using LET, i.e.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;&lt;STRONG&gt;Let&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM style=": ; color: #808080; font-size: 8pt;"&gt;vTest2&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN style="font-size: 8pt;"&gt; = &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Text&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Date&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Today&lt;/SPAN&gt;&lt;SPAN style="font-size: 8pt;"&gt;(),'YYYY')); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;or as Gybert suggested using Year() function.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;If you define it in the variable overview, the Dollar sign expansion in the script will contain the equal sign, leading to&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;WHERE YEAR &amp;lt;= =Text(Date(Today(),'YYYY'))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;--&amp;gt;Syntax invalid&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Oct 2015 09:28:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-a-variable-in-Set-Analysis-and-script/m-p/943969#M648304</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2015-10-22T09:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: Using a variable in Set Analysis and script</title>
      <link>https://community.qlik.com/t5/QlikView/Using-a-variable-in-Set-Analysis-and-script/m-p/943970#M648305</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Alright, that does the trick&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using let the values are created during script execution time but that shouldn't be a problem in my current case. Sadly there's only one answer to mark as the right one. Ruben got me on the right track at first but yours is more precisely.&lt;/P&gt;&lt;P&gt;I also saw the invalid syntax but hoped for another mechanism which unlike dollar expansion would evaluate the function at first.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Gysbert mentioned the Year() function and this one works well but sometimes it is important how the data are formatted and date() gives a better handling imho - combined with text() or num() it should even return the right data type.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Oct 2015 10:16:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-a-variable-in-Set-Analysis-and-script/m-p/943970#M648305</guid>
      <dc:creator />
      <dc:date>2015-10-22T10:16:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using a variable in Set Analysis and script</title>
      <link>https://community.qlik.com/t5/QlikView/Using-a-variable-in-Set-Analysis-and-script/m-p/943971#M648306</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dollar sign expansion will anyway expand the variable to plain constant number in the script code before parsing, so no need to worry about right data types.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.qlik.com/qlik-blogpost/3444"&gt;The Magic of Dollar Expansions&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.qlik.com/qlik-blogpost/2830"&gt;Data Types in QlikView&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would go for just using (as suggested above)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LET vMaxYear = Year(Today() );&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's just much easier to understand.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Oct 2015 12:43:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-a-variable-in-Set-Analysis-and-script/m-p/943971#M648306</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2015-10-22T12:43:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using a variable in Set Analysis and script</title>
      <link>https://community.qlik.com/t5/QlikView/Using-a-variable-in-Set-Analysis-and-script/m-p/943972#M648307</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, If you do LET vMaxYear = Date(Today(), 'YYYY'); --&amp;gt; QV stores the string 2015 and the value 22/10/2015&lt;/P&gt;&lt;P&gt;If you create a text box with expression "=AddMonths(vAño, 3)" --&amp;gt; returns 22/01/2016&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So be aware of what value you're really saving and if you go with the date version consider to use EndYear(), EndMonth(), Today()... as it will change the value you're storing (it will show all as '2015').&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you use LET vMaxYear = &lt;STRONG&gt;Text(&lt;/STRONG&gt;Date(Today(), 'YYYY')&lt;STRONG&gt;)&lt;/STRONG&gt;; --&amp;gt; Then you're storing a text, not a date, and date functions like AddMonths() will fail.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Oct 2015 12:54:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-a-variable-in-Set-Analysis-and-script/m-p/943972#M648307</guid>
      <dc:creator>rubenmarin</dc:creator>
      <dc:date>2015-10-22T12:54:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using a variable in Set Analysis and script</title>
      <link>https://community.qlik.com/t5/QlikView/Using-a-variable-in-Set-Analysis-and-script/m-p/943973#M648308</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well I don't want to fight about it but in my case vMaxYear might be used in comparing combined fields of year and month so it's neccessary to have a 4 char year and a 2 char month - using text(date(today(),'MM')) it is save to have leading 0s for string operations whilst set analysis does not care.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just my two cents - maybe I'll see the perks of year(), month(),.. in the future &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Oct 2015 13:15:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-a-variable-in-Set-Analysis-and-script/m-p/943973#M648308</guid>
      <dc:creator />
      <dc:date>2015-10-22T13:15:23Z</dc:date>
    </item>
  </channel>
</rss>

