<?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: Can I make this code goes faster? in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Can-I-make-this-code-goes-faster/m-p/1038487#M640571</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You should try to avoid iterating with a loop over each table row and peek the values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try to load the table, if you need to create a loop based on a record's value like age use the WHILE clause in your load, something like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOAD Age, iterno() as IterNo&lt;/P&gt;&lt;P&gt;FROM YourTableSource&lt;/P&gt;&lt;P&gt;WHILE Age + Iterno()-1 &amp;lt;= 65;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Iterno() can be used as a counter for each iteration. Then try to implement your transformations using the set of variables as part of the LOAD statements (maybe using the variables or tables, created from the variables).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 Feb 2016 00:30:53 GMT</pubDate>
    <dc:creator>swuehl</dc:creator>
    <dc:date>2016-02-16T00:30:53Z</dc:date>
    <item>
      <title>Can I make this code goes faster?</title>
      <link>https://community.qlik.com/t5/QlikView/Can-I-make-this-code-goes-faster/m-p/1038486#M640570</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm working with a table like the one below, and a lot of variables declared with a "LET"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="97.181818" style="border: 1px solid rgb(0, 0, 0); width: 434.182px; height: 92.1818px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align:center;background-color:#6690BC;color:#ffffff;padding:2px;" valign="middle"&gt;&lt;STRONG&gt;ID&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align:center;background-color:#6690BC;color:#ffffff;padding:2px;" valign="middle"&gt;G&lt;/TH&gt;&lt;TH style="text-align:center;background-color:#6690BC;color:#ffffff;padding:2px;" valign="middle"&gt;&lt;STRONG&gt;Status&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align:center;background-color:#6690BC;color:#ffffff;padding:2px;" valign="middle"&gt;&lt;STRONG&gt;Age&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align:center;background-color:#6690BC;color:#ffffff;padding:2px;" valign="middle"&gt;&lt;STRONG&gt;Density&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align:center;background-color:#6690BC;color:#ffffff;padding:2px;" valign="middle"&gt;&lt;STRONG&gt;Year&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;M&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;R&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;20&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;80%&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;2010&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;2&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;F&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;R&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;26&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;90%&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;2012&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;3&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;F&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;24&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;68%&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: center;"&gt;2013&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The variables are something like this:&lt;/P&gt;&lt;P&gt;LET P11MR20=0.10; &lt;SPAN style="font-size: 13.3333px;"&gt;LET P11MR21=0.50; &lt;SPAN style="font-size: 13.3333px;"&gt;LET P11MR22=0.80; &lt;SPAN style="font-size: 13.3333px;"&gt;LET P11MR23=0.30; &lt;SPAN style="font-size: 13.3333px;"&gt;LET P11MR24=0.65; &lt;SPAN style="font-size: 13.3333px;"&gt;LET P11MR25=0.41;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;LET P21MR20=0.90; &lt;SPAN style="font-size: 13.3333px;"&gt;LET P21MR21=0.50; &lt;SPAN style="font-size: 13.3333px;"&gt;LET P11MR22=0.20; &lt;SPAN style="font-size: 13.3333px;"&gt;LET P11MR23=0.70; &lt;SPAN style="font-size: 13.3333px;"&gt;LET P11MR24=0.35; &lt;SPAN style="font-size: 13.3333px;"&gt;LET P11MR25=0.59;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And the code does this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LET vCantFilasAx = noofrows('Table1'); // I need to work through all the registers of my table&lt;/P&gt;&lt;P&gt;For i=0 to $(vCantFilasAx)-1 &lt;/P&gt;&lt;P&gt;//I save in a variable the data of each row in my Table1&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET vEmpr= Peek('ID',$(i),'Table1');&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET vStatus= Peek('Status',$(i),'Table1');&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET vGender= Peek('G',$(i),'Table1');&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET vAge=Peek('Age',$(i),'Table1');&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET vDens=Peek('Density',$(i),'Table1');&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET vAfil=Peek('Year',$(i),'Table1');&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET vBP=((2015-$(vAfil))*6);&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET vBC=((2015-$(vAfil))*6)*$(vDens);&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF $(vAge)&amp;gt;&lt;STRONG&gt;24&lt;/STRONG&gt; or $(vAge)&amp;lt;14 then&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET vDens=$(vDens);&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET vBCot=$(vBC);&lt;/P&gt;&lt;P&gt;&amp;nbsp; ELSE&lt;/P&gt;&lt;P&gt;&amp;nbsp; Let SumD1=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Let SumD2=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Let TSumD1=0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;//For each age starting with the age declared in the row for each employee&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; For ag=$(vAge) to &lt;STRONG&gt;25 &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//I created new variables in order to use them as an algoritm &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET vP11='P11'&amp;amp; '$(vStatus)' &amp;amp; '$(vGender)'&amp;amp; $(vAge);&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET vP21='P21' &amp;amp; '$(vStatus)' &amp;amp; '$(vGender)' &amp;amp; '$(vAge)';&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET DB1_A=($(vDens)*$(vP11))+((1-$(vDens))*$(vP21)); &lt;/P&gt;&lt;P&gt;&amp;nbsp; LET DB1_B=1-$(DB1_A);&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET DB2_A=($(DB1_A)*$(vP11))+($(DB1_B)*$(vP21)); &lt;/P&gt;&lt;P&gt;&amp;nbsp; LET DB2_B=1-$(DB2_A);&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET DB3_A=($(DB2_A)*$(vP11))+($(DB2_B)*$(vP21)); &lt;/P&gt;&lt;P&gt;&amp;nbsp; LET DB3_B=1-$(DB3_A);&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET DB4_A=($(DB3_A)*$(vP11))+($(DB3_B)*$(vP21)); &lt;/P&gt;&lt;P&gt;&amp;nbsp; LET DB4_B=1-$(DB4_A);&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET DB5_A=($(DB4_A)*$(vP11))+($(DB4_B)*$(vP21)); &lt;/P&gt;&lt;P&gt;&amp;nbsp; LET DB5_B=1-$(DB5_A);&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET DB6_A=($(DB5_A)*$(vP11))+($(DB5_B)*$(vP21)); //let DB6_B=1-$(DB6_A);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET SumD1=$(DB1_A)+$(DB2_A)+$(DB3_A)+$(DB4_A)+$(DB5_A)+$(DB6_A);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET SumD2=$(SumD2)+6;&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET TSumD1=$(SumD1)+$(TSumD1);&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;&amp;nbsp; //Then calculate the fields I'm going to use in one final table&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET vBCot=$(TSumD1)+$(vBC);&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET vDensidad_final=($(vBC)+$(TSumD1))/($(vBP)+$(SumD2));&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET vDensidad=$(vDensidad_final);&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET vEdad=$(vEdad)+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; NEXT&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; END If&lt;/P&gt;&lt;P&gt;&amp;nbsp; Final2:&lt;/P&gt;&lt;P&gt;&amp;nbsp; LOAD&lt;/P&gt;&lt;P&gt;&amp;nbsp; '$(vWorker)' as ID,&lt;/P&gt;&lt;P&gt;&amp;nbsp; '$(vDens)' as FinalDens,&lt;/P&gt;&lt;P&gt;&amp;nbsp; '$(vBCot)' as BimCot&lt;/P&gt;&lt;P&gt;&amp;nbsp; AutoGenerate 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; LET vBCot=0;&lt;/P&gt;&lt;P&gt;NEXT&lt;/P&gt;&lt;P&gt;LET vBP=0;&lt;/P&gt;&lt;P&gt;LET vBC=0;&lt;/P&gt;&lt;P&gt;Store Final2 into Final2.qvd (qvd);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The thing is, actually I have to run this until age 65, I have 50 million rows and 312 variables for each age. Table1 is a qvd, and I try this with data of 3million employees and the whole execution took me 35 hrs...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there something I'm doing wrong or that i can do better?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Feb 2016 18:37:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Can-I-make-this-code-goes-faster/m-p/1038486#M640570</guid>
      <dc:creator />
      <dc:date>2016-02-15T18:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: Can I make this code goes faster?</title>
      <link>https://community.qlik.com/t5/QlikView/Can-I-make-this-code-goes-faster/m-p/1038487#M640571</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You should try to avoid iterating with a loop over each table row and peek the values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try to load the table, if you need to create a loop based on a record's value like age use the WHILE clause in your load, something like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOAD Age, iterno() as IterNo&lt;/P&gt;&lt;P&gt;FROM YourTableSource&lt;/P&gt;&lt;P&gt;WHILE Age + Iterno()-1 &amp;lt;= 65;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Iterno() can be used as a counter for each iteration. Then try to implement your transformations using the set of variables as part of the LOAD statements (maybe using the variables or tables, created from the variables).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Feb 2016 00:30:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Can-I-make-this-code-goes-faster/m-p/1038487#M640571</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2016-02-16T00:30:53Z</dc:date>
    </item>
  </channel>
</rss>

