<?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: Using loops in script in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576457#M683450</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't think a loop is necessary here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load your table in itemcode, period order&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then for your monthly cost field use this expression:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If(isnull([monthly cost] and itemcode = peek('itemcode', -1),&lt;/P&gt;&lt;P&gt; peek('NewMonthlyCost', -1),&lt;/P&gt;&lt;P&gt; [monthly cost]) as NewMonthlyCost&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 14 Mar 2014 12:34:03 GMT</pubDate>
    <dc:creator>marcus_malinow</dc:creator>
    <dc:date>2014-03-14T12:34:03Z</dc:date>
    <item>
      <title>Using loops in script</title>
      <link>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576455#M683448</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have 2 tables with monthly costs and monthly income (pic1).&lt;/P&gt;&lt;P&gt;I have a request to display monthly costs per items sold .&lt;/P&gt;&lt;P&gt;For months which costs are not available, I have to use the last recorded cost.&lt;/P&gt;&lt;P&gt;There can be few months missing.&lt;/P&gt;&lt;P&gt;For example , for January 2014 and February 2014, I have to use the cost value from December 2013 (pic2).&lt;/P&gt;&lt;P&gt;I was thinking of using For-Next loops and Peek to go over both tables and create the third. &lt;/P&gt;&lt;P&gt;Is there a better alternative?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 12:27:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576455#M683448</guid>
      <dc:creator />
      <dc:date>2014-03-14T12:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using loops in script</title>
      <link>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576456#M683449</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can use Peek &amp;amp; Previous function in Script to create the desired result.&lt;/P&gt;&lt;P&gt;Another option is to use Above and Below or Before and After function in Straight or Pivot table.&lt;/P&gt;&lt;P&gt;If you can provide sample data, can help you better way.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 12:32:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576456#M683449</guid>
      <dc:creator>MK_QSL</dc:creator>
      <dc:date>2014-03-14T12:32:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using loops in script</title>
      <link>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576457#M683450</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't think a loop is necessary here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load your table in itemcode, period order&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then for your monthly cost field use this expression:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If(isnull([monthly cost] and itemcode = peek('itemcode', -1),&lt;/P&gt;&lt;P&gt; peek('NewMonthlyCost', -1),&lt;/P&gt;&lt;P&gt; [monthly cost]) as NewMonthlyCost&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 12:34:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576457#M683450</guid>
      <dc:creator>marcus_malinow</dc:creator>
      <dc:date>2014-03-14T12:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using loops in script</title>
      <link>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576458#M683451</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can use For / Next loops in a QlikView load script - and I will often enumerate around source files in a folder or rows in an existing table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are neater ways of achieving what you are after though.&amp;nbsp; The best explanation I have seen of this is by &lt;A href="https://community.qlik.com/qlik-users/4003"&gt;Henric Cronström&lt;/A&gt; in his blog posting: &lt;A _jive_internal="true" href="https://community.qlik.com/blogs/qlikviewdesignblog/2013/02/05/populating-a-sparsely-populated-field" title="http://community.qlik.com/blogs/qlikviewdesignblog/2013/02/05/populating-a-sparsely-populated-field"&gt;http://community.qlik.com/blogs/qlikviewdesignblog/2013/02/05/populating-a-sparsely-populated-field&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The reference to the WHILE statement in the comments is also very useful - you can build a loop right into your load statement in a preceding load.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;P&gt;Steve&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 12:34:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576458#M683451</guid>
      <dc:creator>stevedark</dc:creator>
      <dc:date>2014-03-14T12:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using loops in script</title>
      <link>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576459#M683452</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, I wouldn't use any For-Next Loop. I would suggest the below approach -&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Costs_temp:&lt;/P&gt;&lt;P&gt;Load Month&lt;/P&gt;&lt;P&gt;From Invoices&amp;nbsp;&amp;nbsp; //Assuming your Invoice table would have all the months&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Left Join (Cost_Temp)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load Month,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Cost1&lt;/P&gt;&lt;P&gt;From Costs;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Costs:&lt;/P&gt;&lt;P&gt; Load *&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(isnull(Cost1)&amp;lt;0, peek(Cost1), Cost1) as Cost&lt;/P&gt;&lt;P&gt;Resident Costs_temp&lt;/P&gt;&lt;P&gt;Order by month&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The idea would be to populate preceding month's Cost in case current month's cost is NULL.&lt;/P&gt;&lt;P&gt;Hope this is of help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;SK&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 12:39:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576459#M683452</guid>
      <dc:creator />
      <dc:date>2014-03-14T12:39:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using loops in script</title>
      <link>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576460#M683453</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would say:&lt;/P&gt;&lt;P&gt;in the script&lt;/P&gt;&lt;P&gt;JOIN the two tables&lt;/P&gt;&lt;P&gt;Sort by Dates&lt;/P&gt;&lt;P&gt;Use peek&amp;nbsp; (as shown above, test that the item code is the same as the one of the previous line)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Fabrice&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 12:40:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576460#M683453</guid>
      <dc:creator />
      <dc:date>2014-03-14T12:40:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using loops in script</title>
      <link>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576461#M683454</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Marcus,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think it won't work when there are more the one month missing a cost value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 12:40:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576461#M683454</guid>
      <dc:creator />
      <dc:date>2014-03-14T12:40:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using loops in script</title>
      <link>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576462#M683455</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, it will, as it will carry the value from the last populated record&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 12:43:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576462#M683455</guid>
      <dc:creator>marcus_malinow</dc:creator>
      <dc:date>2014-03-14T12:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using loops in script</title>
      <link>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576463#M683456</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have the solution into the document &lt;A _jive_internal="true" class="loading" href="https://community.qlik.com/docs/DOC-5698" title="http://community.qlik.com/docs/DOC-5698"&gt;http://community.qlik.com/docs/DOC-5698&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Specific chapter on &lt;STRONG&gt;peek&lt;/STRONG&gt;() or &lt;STRONG&gt;previous&lt;/STRONG&gt;()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Fabrice&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 12:47:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576463#M683456</guid>
      <dc:creator />
      <dc:date>2014-03-14T12:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: Re: Using loops in script</title>
      <link>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576464#M683457</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Manish,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Attached are the tables.&lt;/P&gt;&lt;P&gt;Please note that I'm using&amp;nbsp; a free PE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your kind help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 12:47:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576464#M683457</guid>
      <dc:creator />
      <dc:date>2014-03-14T12:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using loops in script</title>
      <link>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576465#M683458</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you all!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I find the references very useful too!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2014 13:24:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-loops-in-script/m-p/576465#M683458</guid>
      <dc:creator />
      <dc:date>2014-03-14T13:24:47Z</dc:date>
    </item>
  </channel>
</rss>

