<?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: Proper syntax for FOR..NEXT loop and LOAD statement in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Proper-syntax-for-FOR-NEXT-loop-and-LOAD-statement/m-p/955618#M647564</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't see why if then won't work within FOR loop. but to get the syntax right, I would prefer having the script so that I can test run it. I know some other experts may be able to help you just by looking at the code, but if possible would you be able to share a app with some data and the above mentioned code where it doesn't seem to be working?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Sunny&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 23 Oct 2015 18:36:19 GMT</pubDate>
    <dc:creator>sunny_talwar</dc:creator>
    <dc:date>2015-10-23T18:36:19Z</dc:date>
    <item>
      <title>Proper syntax for FOR..NEXT loop and LOAD statement</title>
      <link>https://community.qlik.com/t5/QlikView/Proper-syntax-for-FOR-NEXT-loop-and-LOAD-statement/m-p/955617#M647563</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We break our sales down into five stages, 00, 20, 40, 60, 80. I have to find out how long it takes between each stage, and set the background colour in red for that one. I have a table created in my script, OM, that includes&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OM:&lt;/P&gt;&lt;P&gt;Select&lt;/P&gt;&lt;P&gt;Company,&lt;/P&gt;&lt;P&gt;OPID, &amp;lt;- Opp ID, a unique 16-char field that identifies each opp'y&lt;/P&gt;&lt;P&gt;Stage,&lt;/P&gt;&lt;P&gt;OnDate,&lt;/P&gt;&lt;P&gt;(other fields)&lt;/P&gt;&lt;P&gt;from database&lt;/P&gt;&lt;P&gt;ORDER BY&lt;/P&gt;&lt;P&gt;Company, OPID, OnDate&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, each company can have many opportunities, and most opportunities do NOT include all the five stages, so I wanted to do the calculation in the script by first ensuring that two adjacent records are for the same company and the same OPID. If so, I subtract one from the other. I have immediately under my ORDER BY statement above&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;UNQUALIFY OPID;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For i = 0 to NoOfRows('OM')-1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF peek('COMPANY',i,'OM') = &lt;SPAN style="font-size: 13.3333px;"&gt;peek('COMPANY',i+1,'OM') THEN&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF peek('OPID',i,'OM') = &lt;SPAN style="font-size: 13.3333px;"&gt;peek('OPID',i+1,'OM') THEN&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; StDiff: //Note: I tried with and without this table label. Same error each time&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; LOAD&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OPID, // loaded to link files&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; peek('OnDate',i+1,'OM')-peek('OnDate',i,'OM') as StageDiff,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ENDIF&lt;/P&gt;&lt;P&gt;ENDIF&lt;/P&gt;&lt;P&gt;Next i&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This completes without error, but the field "StageDiff" is nowhere to be found.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can I use an IF THEN ELSE within a FOR NEXT loop?&lt;/P&gt;&lt;P&gt;Can I have a LOAD statement inside an IF THEN ELSE?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any other ideas on how to do this correctly?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Oct 2015 18:28:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Proper-syntax-for-FOR-NEXT-loop-and-LOAD-statement/m-p/955617#M647563</guid>
      <dc:creator />
      <dc:date>2015-10-23T18:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: Proper syntax for FOR..NEXT loop and LOAD statement</title>
      <link>https://community.qlik.com/t5/QlikView/Proper-syntax-for-FOR-NEXT-loop-and-LOAD-statement/m-p/955618#M647564</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't see why if then won't work within FOR loop. but to get the syntax right, I would prefer having the script so that I can test run it. I know some other experts may be able to help you just by looking at the code, but if possible would you be able to share a app with some data and the above mentioned code where it doesn't seem to be working?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Sunny&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Oct 2015 18:36:19 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Proper-syntax-for-FOR-NEXT-loop-and-LOAD-statement/m-p/955618#M647564</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2015-10-23T18:36:19Z</dc:date>
    </item>
    <item>
      <title>Re: Proper syntax for FOR..NEXT loop and LOAD statement</title>
      <link>https://community.qlik.com/t5/QlikView/Proper-syntax-for-FOR-NEXT-loop-and-LOAD-statement/m-p/955619#M647568</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Look for below example;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin: 0 0 1.2em; color: #000000; font-family: Verdana, Geneva, sans-serif; font-size: 13px;"&gt;&lt;EM&gt;Sub LoadTableNames&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;SQLTableList:&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;LOAD&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Name AS TableNames;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;SELECT Name FROM ContosoRetailDW.sys.tables;&lt;/EM&gt;&lt;/P&gt;&lt;P style="margin: 0 0 1.2em; color: #000000; font-family: Verdana, Geneva, sans-serif; font-size: 13px;"&gt;&lt;EM&gt;End Sub;&lt;/EM&gt;&lt;/P&gt;&lt;P style="margin: 0 0 1.2em; color: #000000; font-family: Verdana, Geneva, sans-serif; font-size: 13px;"&gt;&lt;EM&gt;// ======================================================//&lt;/EM&gt;&lt;/P&gt;&lt;P style="margin: 0 0 1.2em; color: #000000; font-family: Verdana, Geneva, sans-serif; font-size: 13px;"&gt;&lt;EM&gt;Call LoadTableNames;&lt;/EM&gt;&lt;/P&gt;&lt;P style="margin: 0 0 1.2em; color: #000000; font-family: Verdana, Geneva, sans-serif; font-size: 13px;"&gt;&lt;EM&gt;// ======================================================//&lt;/EM&gt;&lt;/P&gt;&lt;P style="margin: 0 0 1.2em; color: #000000; font-family: Verdana, Geneva, sans-serif; font-size: 13px;"&gt;&lt;EM&gt;Let vTableCount = NoOfRows(‘SQLTableList’);&lt;/EM&gt;&lt;/P&gt;&lt;P style="margin: 0 0 1.2em; color: #000000; font-family: Verdana, Geneva, sans-serif; font-size: 13px;"&gt;&lt;EM&gt;// ======================================================//&lt;/EM&gt;&lt;/P&gt;&lt;P style="margin: 0 0 1.2em; color: #000000; font-family: Verdana, Geneva, sans-serif; font-size: 13px;"&gt;&lt;EM&gt;Sub LoadTableData&lt;/EM&gt;&lt;/P&gt;&lt;P style="margin: 0 0 1.2em; color: #000000; font-family: Verdana, Geneva, sans-serif; font-size: 13px;"&gt;&lt;EM&gt;For i = 0 To $(vTableCount) – 1&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;LET vMyTableName = Peek(‘TableNames’, $(i), ‘SQLTableList’);&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;$(vMyTableName):&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;SQL SELECT * FROM ContosoRetailDW.dbo.$(vMyTableName);&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;STORE $(vMyTableName) INTO $(Directory)$(vMyTableName).QVD;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;DROP Table $(vMyTableName);&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Next i&lt;/EM&gt;&lt;/P&gt;&lt;P style="margin: 0 0 1.2em; color: #000000; font-family: Verdana, Geneva, sans-serif; font-size: 13px;"&gt;&lt;EM&gt;End Sub;&lt;/EM&gt;&lt;/P&gt;&lt;P style="margin: 0 0 1.2em; color: #000000; font-family: Verdana, Geneva, sans-serif; font-size: 13px;"&gt;&lt;EM&gt;// ==========================================================================================//&lt;/EM&gt;&lt;/P&gt;&lt;P style="margin: 0 0 1.2em; color: #000000; font-family: Verdana, Geneva, sans-serif; font-size: 13px;"&gt;&lt;EM&gt;Call LoadTableData;&lt;/EM&gt;&lt;/P&gt;&lt;P style="margin: 0 0 1.2em; color: #000000; font-family: Verdana, Geneva, sans-serif; font-size: 13px;"&gt;&lt;EM&gt;// ==========================================================================================//&lt;/EM&gt;&lt;/P&gt;&lt;P style="margin: 0 0 1.2em; color: #000000; font-family: Verdana, Geneva, sans-serif; font-size: 13px;"&gt;&lt;EM&gt; &lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Oct 2015 18:37:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Proper-syntax-for-FOR-NEXT-loop-and-LOAD-statement/m-p/955619#M647568</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-10-23T18:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Proper syntax for FOR..NEXT loop and LOAD statement</title>
      <link>https://community.qlik.com/t5/QlikView/Proper-syntax-for-FOR-NEXT-loop-and-LOAD-statement/m-p/955620#M647571</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks, Imran, but I think my issue has to do with the fact that my LOAD statement is nested in two IF statements,&lt;/P&gt;&lt;P&gt;which I don't see in your example above. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As I said, my script completes without error, but "StageDiff" does not get added to either the existing OM table, nor does it get added to the StDiff: table I tried to create (and as I noted, regardless of whether that table label is present or not, the script completes but the data disappears). &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Oct 2015 19:06:00 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Proper-syntax-for-FOR-NEXT-loop-and-LOAD-statement/m-p/955620#M647571</guid>
      <dc:creator />
      <dc:date>2015-10-23T19:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: Proper syntax for FOR..NEXT loop and LOAD statement</title>
      <link>https://community.qlik.com/t5/QlikView/Proper-syntax-for-FOR-NEXT-loop-and-LOAD-statement/m-p/955621#M647573</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I made some changes in my code, and found the following.&lt;/P&gt;&lt;P&gt;First, the new code (contains some lines so I could watch the debugger)&lt;/P&gt;&lt;P&gt;&lt;IMG alt="spcode.PNG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/102953_spcode.PNG" style="height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;In a limited load using the debugger, I noted that the first two lines of the OM file had the same company and the same OPID, so I would have expected that after the statement&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if peek('OPID',i,'OM')=peek('OPID",i+1,'OM)&lt;/P&gt;&lt;P&gt;it would try to execute the LOAD statement.However, the debugger just showed it skipping directly to the ENDIF's. Here's a screen grab from the debugger, showing COMP1=COMP2 AND OP1=OP2. &lt;/P&gt;&lt;P&gt;&lt;IMG alt="spcode2.png" class="jive-image image-2" src="https://community.qlik.com/legacyfs/online/102954_spcode2.png" style="height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But the "THEN" statement (i.e. the LOAD block) is not executing. I can't figure out why, unless this is not supported, and the non-support is not documented. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Oct 2015 19:21:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Proper-syntax-for-FOR-NEXT-loop-and-LOAD-statement/m-p/955621#M647573</guid>
      <dc:creator />
      <dc:date>2015-10-23T19:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: Proper syntax for FOR..NEXT loop and LOAD statement</title>
      <link>https://community.qlik.com/t5/QlikView/Proper-syntax-for-FOR-NEXT-loop-and-LOAD-statement/m-p/955622#M647576</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OM:&lt;/P&gt;&lt;P&gt;Load&lt;/P&gt;&lt;P&gt;*,&lt;/P&gt;&lt;P&gt;if(Company=Previous(Company) and OPID=Previous(OPID),OnDate-Previous(OnDate)) as StageDiff&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;Select&lt;/P&gt;&lt;P&gt;Company,&lt;/P&gt;&lt;P&gt;OPID,&lt;/P&gt;&lt;P&gt;Stage,&lt;/P&gt;&lt;P&gt;OnDate,&lt;/P&gt;&lt;P&gt;(other fields)&lt;/P&gt;&lt;P&gt;from database&lt;/P&gt;&lt;P&gt;ORDER BY&lt;/P&gt;&lt;P&gt;Company, OPID, OnDate&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Oct 2015 19:23:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Proper-syntax-for-FOR-NEXT-loop-and-LOAD-statement/m-p/955622#M647576</guid>
      <dc:creator>cwolf</dc:creator>
      <dc:date>2015-10-23T19:23:25Z</dc:date>
    </item>
    <item>
      <title>Re: Proper syntax for FOR..NEXT loop and LOAD statement</title>
      <link>https://community.qlik.com/t5/QlikView/Proper-syntax-for-FOR-NEXT-loop-and-LOAD-statement/m-p/955623#M647577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, Christian. I wasn't aware of the "Previous" function, and wouldn't have thought of it in any case, as the table is not sorted by company coming in. However, after looking at what you suggested, it dawned on me that the LOAD statement gets executed AFTER the OM table is built, and hence it would already be ordered by Company, OPID, OnDate. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks a bunch to everyone!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 Oct 2015 19:51:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Proper-syntax-for-FOR-NEXT-loop-and-LOAD-statement/m-p/955623#M647577</guid>
      <dc:creator />
      <dc:date>2015-10-23T19:51:18Z</dc:date>
    </item>
  </channel>
</rss>

