<?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: For loop not working as expected in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/For-loop-not-working-as-expected/m-p/2048913#M1222933</link>
    <description>&lt;P&gt;Hi &lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/3349"&gt;@vikasshana&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Because the p1-loop is nested in the p-loop, I'd say that you'll have to switch "next p" and "next p1".&lt;/P&gt;</description>
    <pubDate>Tue, 14 Mar 2023 10:56:28 GMT</pubDate>
    <dc:creator>Marijn</dc:creator>
    <dc:date>2023-03-14T10:56:28Z</dc:date>
    <item>
      <title>For loop not working as expected</title>
      <link>https://community.qlik.com/t5/QlikView/For-loop-not-working-as-expected/m-p/2048857#M1222932</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I've below code in my load script.&lt;/P&gt;
&lt;P&gt;LET vFiscalPeriodID=If(Month(now())=1,Year(Now())-1&amp;amp;'.012',Left(Year(Now()),4)&amp;amp;'.'&amp;amp;right(1000+Month(Now())-1,3));&lt;BR /&gt;//vFiscalPeriodID='2016.012'&lt;BR /&gt;LET vFiscalPeriodID2=Replace('$(vFiscalPeriodID)','.','');&lt;BR /&gt;LET vFiscalYear=left($(vFiscalPeriodID),4);&lt;BR /&gt;LET vExchangeRateYear=$(vFiscalYear);&lt;BR /&gt;LET vCurrentMonth = Month(Now())-1;&lt;BR /&gt;LET vNextMonth = num(Month(Now()));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For p=1 to 12;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LET vCY_loop= $(vFiscalYear)*1000+$(p);&lt;BR /&gt;LET vCY_loop2= left($(vCY_loop),4)&amp;amp;'.'&amp;amp;right($(vCY_loop),3);&lt;BR /&gt;LET vLY_loop= ($(vFiscalYear)-1)*1000+$(p);&lt;BR /&gt;LET vLY_loop2= left($(vLY_loop),4)&amp;amp;'.'&amp;amp;right($(vLY_loop),3);&lt;BR /&gt;LET vPeriod_loop = right($(vCY_loop),3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For p1=3 to 12;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LET vCY_loops= $(vFiscalYear)*1000+$(p1);&lt;BR /&gt;LET vCY_loops2= left($(vCY_loops),4)&amp;amp;'.'&amp;amp;right($(vCY_loops),3);&lt;BR /&gt;LET vLY_loops= ($(vFiscalYear)-1)*1000+$(p1);&lt;BR /&gt;LET vLY_loops2= left($(vLY_loops),4)&amp;amp;'.'&amp;amp;right($(vLY_loops),3);&lt;BR /&gt;LET vPeriod_loops = right($(vCY_loops),3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If $(p)&amp;lt;=$(vCurrentMonth) then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Test:&lt;BR /&gt;Load *, Current&lt;BR /&gt;from [..../test.xlsx] where [Fiscal Period] = [$(vCY_loop2)];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;STORE Test INTO [..\..\Test_$(vPeriod_loop).QVD] (QVD);&lt;BR /&gt;Drop table Test;&lt;BR /&gt;End if;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If $(p1)&amp;gt;=$(vNextMonth) then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Test2:&lt;BR /&gt;Load *, Later&lt;BR /&gt;from [..../test.xlsx] where [Fiscal Period] = [$(vCY_loops2)];&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;STORE Test2 INTO [..\..\Test_$(vPeriod_loop).QVD] (QVD);&lt;BR /&gt;Drop table Test2;&lt;BR /&gt;End if;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;next p;&lt;BR /&gt;next p1;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;The output I'm looking for the first &lt;STRONG&gt;IF&lt;/STRONG&gt; statement it has to start the loop from '&lt;STRONG&gt;1&lt;/STRONG&gt;' and has to end at '&lt;STRONG&gt;2&lt;/STRONG&gt;' where it creates two QVD's and the second &lt;STRONG&gt;IF&lt;/STRONG&gt; statement&amp;nbsp;it has to start the loop from '&lt;STRONG&gt;3'&lt;/STRONG&gt; and has to end at '&lt;STRONG&gt;12&lt;/STRONG&gt;'&amp;nbsp;where it creates &lt;STRONG&gt;9&lt;/STRONG&gt; QVD's. But for now for the first and second &lt;STRONG&gt;IF&lt;/STRONG&gt; statements it is creating only &lt;STRONG&gt;1&lt;/STRONG&gt; QVD and ending the loop and receiving error message.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class="ui-provider wd b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak"&gt;Next p&lt;BR /&gt;&amp;nbsp; Error:&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;End if&lt;BR /&gt;&amp;nbsp; &lt;STRONG&gt;Error: The control statement is not correctly matched with its corresponding start statement&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class="ui-provider wd b c d e f g h i j k l m n o p q r s t u v w x y z ab ac ae af ag ah ai aj ak"&gt;&lt;STRONG&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/42758"&gt;@PrashantSangle&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/22949"&gt;@tresB&lt;/a&gt;&amp;nbsp;&lt;/STRONG&gt;can you help me with this?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 09:26:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/For-loop-not-working-as-expected/m-p/2048857#M1222932</guid>
      <dc:creator>vikasshana</dc:creator>
      <dc:date>2023-03-14T09:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: For loop not working as expected</title>
      <link>https://community.qlik.com/t5/QlikView/For-loop-not-working-as-expected/m-p/2048913#M1222933</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/3349"&gt;@vikasshana&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Because the p1-loop is nested in the p-loop, I'd say that you'll have to switch "next p" and "next p1".&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 10:56:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/For-loop-not-working-as-expected/m-p/2048913#M1222933</guid>
      <dc:creator>Marijn</dc:creator>
      <dc:date>2023-03-14T10:56:28Z</dc:date>
    </item>
  </channel>
</rss>

