<?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 Loop from an array in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Loop-from-an-array/m-p/214765#M503096</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to build a script with a loop based on a variable array. My variable can be set as: vYears= '2008,2009,2010'. The loop should then read 2008 and do something with it, read 2009 and do something with it etc. The set of variables is defined by a user. So, I need first to read the array, create a new variable with each year and loop.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 05 Jul 2010 18:21:27 GMT</pubDate>
    <dc:creator />
    <dc:date>2010-07-05T18:21:27Z</dc:date>
    <item>
      <title>Loop from an array</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-from-an-array/m-p/214765#M503096</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to build a script with a loop based on a variable array. My variable can be set as: vYears= '2008,2009,2010'. The loop should then read 2008 and do something with it, read 2009 and do something with it etc. The set of variables is defined by a user. So, I need first to read the array, create a new variable with each year and loop.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Jul 2010 18:21:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-from-an-array/m-p/214765#M503096</guid>
      <dc:creator />
      <dc:date>2010-07-05T18:21:27Z</dc:date>
    </item>
    <item>
      <title>Loop from an array</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-from-an-array/m-p/214766#M503097</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="hcp7"&gt;for i=1 to substringcount ( vYears, ',' )&lt;/P&gt;&lt;P class="hcp8"&gt;subfield(vYears, ',' ,i)&lt;/P&gt;&lt;P class="hcp16"&gt;next&lt;/P&gt;&lt;P class="hcp16"&gt;Something like this!!!&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Jul 2010 18:34:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-from-an-array/m-p/214766#M503097</guid>
      <dc:creator />
      <dc:date>2010-07-05T18:34:24Z</dc:date>
    </item>
    <item>
      <title>Loop from an array</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-from-an-array/m-p/214767#M503098</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Patrick, you can also use the for each syntax. To accomplish this, you would have to declare your variable similar to:&lt;/P&gt;&lt;P&gt;set vYears = '2008','2009','2010'&lt;/P&gt;&lt;P&gt;Then use the for each:&lt;/P&gt;&lt;P&gt;for each y in $(vYears)&lt;/P&gt;&lt;P&gt;statements...&lt;/P&gt;&lt;P&gt;next&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Jul 2010 18:40:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-from-an-array/m-p/214767#M503098</guid>
      <dc:creator />
      <dc:date>2010-07-05T18:40:12Z</dc:date>
    </item>
    <item>
      <title>Loop from an array</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-from-an-array/m-p/214768#M503099</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ivan, this works finr for years, thanks. However, if I have:&lt;/P&gt;&lt;P&gt;set vSomething = 'aaa', 'bbb';&lt;/P&gt;&lt;P&gt;for each s in $(vSomething) I get the value NULL for s.&lt;/P&gt;&lt;P&gt;Any clue?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Jul 2010 21:06:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-from-an-array/m-p/214768#M503099</guid>
      <dc:creator />
      <dc:date>2010-07-05T21:06:13Z</dc:date>
    </item>
    <item>
      <title>Loop from an array</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-from-an-array/m-p/214769#M503100</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Patrick, it strongly depends in the context you use the variable 's', two general scenarios come to my mind:&lt;/P&gt;&lt;P&gt;1. If you expanded the variable like this:&lt;/P&gt;&lt;P&gt;$(s) , qlikview would look for a variable named aaa in the first iteration, since it doesnt find such variable it returns null.&lt;/P&gt;&lt;P&gt;2. if you can to use the s variable as an string, you have to encapsulate the expansion into single quotes, like this:&lt;/P&gt;&lt;P&gt;'$(s)', this way the value would be render as an string.&lt;/P&gt;&lt;P&gt;Hope this helps you.&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Jul 2010 21:15:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-from-an-array/m-p/214769#M503100</guid>
      <dc:creator />
      <dc:date>2010-07-05T21:15:25Z</dc:date>
    </item>
    <item>
      <title>Loop from an array</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-from-an-array/m-p/214770#M503101</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My code was missing the single quote as you explained. Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Jul 2010 21:22:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-from-an-array/m-p/214770#M503101</guid>
      <dc:creator />
      <dc:date>2010-07-05T21:22:20Z</dc:date>
    </item>
    <item>
      <title>Loop from an array</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-from-an-array/m-p/214771#M503102</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have to add something to the discussion:&lt;/P&gt;&lt;P&gt;If the variable vStuff has 2+ string parameter. The iteration using a for...next works fine. However, if there is only one parameter, it returns NULL.&lt;/P&gt;&lt;P&gt;Assume the following code:&lt;/P&gt;&lt;P&gt;&lt;I&gt;for each s in $(vStuff)&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;I&gt;something happens&lt;/I&gt;&lt;/P&gt;&lt;P style="font-style: italic"&gt;next&lt;/P&gt;&lt;P&gt;If vStuff = '2010'; - works fine&lt;/P&gt;&lt;P&gt;If vStuff = '2009', '2010'; - works fine&lt;/P&gt;&lt;P&gt;If vStuff = 'aaa','bbb'; - works fine&lt;/P&gt;&lt;P&gt;If vStuff = 'aaa'; Doesn't work. s is set to NULL.&lt;/P&gt;&lt;P&gt;Is this supposed to be a normal behaviour?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Jul 2010 08:52:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-from-an-array/m-p/214771#M503102</guid>
      <dc:creator />
      <dc:date>2010-07-06T08:52:29Z</dc:date>
    </item>
    <item>
      <title>Loop from an array</title>
      <link>https://community.qlik.com/t5/QlikView/Loop-from-an-array/m-p/214772#M503103</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Interesting, it never ocurred to me before. What I see, is that when you expand a single token string, QlikView again thinks is the name on a variable, to solve this problem, you can declare your variable as follows:&lt;/P&gt;&lt;P&gt;set vStuff="'aaa','bbb'";&lt;/P&gt;&lt;P&gt;set vStuff="'aaa'";&lt;/P&gt;&lt;P&gt;Notice the declaration is the same as before, but with an addition of double quotes encapsulating the tokens, this way you should not have any problem, no matter the quantity of tokens.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Jul 2010 14:48:19 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Loop-from-an-array/m-p/214772#M503103</guid>
      <dc:creator />
      <dc:date>2010-07-06T14:48:19Z</dc:date>
    </item>
  </channel>
</rss>

