<?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 for next loop taking loading time 6 hrs in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/using-for-next-loop-taking-loading-time-6-hrs/m-p/1738863#M56492</link>
    <description>&lt;P&gt;I think it's a great example of how it should &lt;STRONG&gt;not&lt;/STRONG&gt; be done ... Even with small datasets it will run quite long times ...&lt;/P&gt;&lt;P&gt;The reason for it is you pick each single record from your source within an outside-loop, nest then another outside-loop to create multiple additionally records in regard to the periods and load then from the source with multiple condition in a where-clause which means that each time the whole source is accessed to check the conditions and to load the data with your other transformations.&lt;/P&gt;&lt;P&gt;I think the same could be reached by using an inside-loop with while - simplified something in that way:&lt;/P&gt;&lt;P&gt;load date(floor(addmonths(Date1, iterno() -1))) as Date1, [further fields ...]&lt;BR /&gt;from source while iterno() &amp;lt;= MonthDiff(Date1, Date2);&lt;/P&gt;&lt;P&gt;- Marcus&lt;/P&gt;</description>
    <pubDate>Wed, 26 Aug 2020 14:30:10 GMT</pubDate>
    <dc:creator>marcus_sommer</dc:creator>
    <dc:date>2020-08-26T14:30:10Z</dc:date>
    <item>
      <title>using for next loop taking loading time 6 hrs</title>
      <link>https://community.qlik.com/t5/App-Development/using-for-next-loop-taking-loading-time-6-hrs/m-p/1738809#M56479</link>
      <description>&lt;P&gt;Set MonthDiff = Num(((year($2) * 12) + month($2)) - (((year($1) * 12) + month($1))) + 1);&lt;/P&gt;&lt;P&gt;[Outlets]:&lt;BR /&gt;Load&lt;BR /&gt;OutletID,&lt;BR /&gt;City,&lt;BR /&gt;Province,&lt;BR /&gt;Region,&lt;BR /&gt;Distributor,&lt;BR /&gt;Opening_Date,&lt;BR /&gt;Start_Date,&lt;BR /&gt;Closing_Date,&lt;BR /&gt;MonthlyOutletRental,&lt;BR /&gt;"OutletSize(Sq meter)",&lt;BR /&gt;"# of shop assistants",&lt;BR /&gt;PayrollCost&lt;BR /&gt;FROM [lib://Tupperware Data QVD (hpserver_qsadmin)/AllOutlets.qvd]&lt;BR /&gt;(qvd);&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;NoConcatenate&lt;/P&gt;&lt;P&gt;[AllOutlets]:&lt;BR /&gt;Load&lt;BR /&gt;OutletID,&lt;BR /&gt;City,&lt;BR /&gt;Province,&lt;BR /&gt;Region,&lt;BR /&gt;Distributor,&lt;BR /&gt;Opening_Date,&lt;BR /&gt;Start_Date,&lt;BR /&gt;Closing_Date,&lt;BR /&gt;MonthlyOutletRental,&lt;BR /&gt;"OutletSize(Sq meter)",&lt;BR /&gt;"# of shop assistants",&lt;BR /&gt;PayrollCost&lt;BR /&gt;Resident Outlets&lt;BR /&gt;order by Opening_Date desc, Closing_Date desc;&lt;/P&gt;&lt;P&gt;Drop Table Outlets;&lt;/P&gt;&lt;P&gt;[Temp1]:&lt;BR /&gt;Load&lt;BR /&gt;if(max(Opening_Date)&amp;gt;max(Closing_Date),max(Opening_Date),max(Closing_Date)) as Opening_Date&lt;BR /&gt;Resident AllOutlets;&lt;/P&gt;&lt;P&gt;//Let vMaxDate = date(monthend(today()),'DD-MM-YYYY');&lt;/P&gt;&lt;P&gt;Let vMaxDate = peek('Opening_Date', 0, 'Temp1');&lt;BR /&gt;trace 'Max Date'&amp;amp;$(vMaxDate);&lt;/P&gt;&lt;P&gt;//for i = 0 to NoOfRows('AllOutlets')&lt;BR /&gt;for i = 0 to 10&lt;BR /&gt;Let vOutletID = peek('OutletID', $(i), 'AllOutlets');&lt;BR /&gt;Let vCity = peek('City', $(i), 'AllOutlets');&lt;BR /&gt;Let vProvince = peek('Province', $(i), 'AllOutlets');&lt;BR /&gt;Let vRegion = peek('Region', $(i), 'AllOutlets');&lt;BR /&gt;Let vDistributor = peek('Distributor', $(i), 'AllOutlets');&lt;BR /&gt;Let vOpening_Date = peek('Opening_Date', $(i), 'AllOutlets');&lt;BR /&gt;Let vClosing_Date = peek('Closing_Date', $(i), 'AllOutlets');&lt;BR /&gt;Let vOutletRental = peek('MonthlyOutletRental', $(i), 'AllOutlets');&lt;BR /&gt;Let vOutletSize = peek('"OutletSize(Sq meter)"', $(i), 'AllOutlets');&lt;BR /&gt;Let vNumofassist = peek('"# of shop assistants"', $(i), 'AllOutlets');&lt;BR /&gt;Let vPayrollCost = peek('PayrollCost', $(i), 'AllOutlets');&lt;BR /&gt;&lt;BR /&gt;Let vCloseDate2 = if(len(trim('$(vClosing_Date)')) &amp;gt; 0,'$(vClosing_Date)','$(vMaxDate)');&lt;BR /&gt;Let vCloseDate3 = Date(DATE#(vCloseDate2,'DD-MM-YYYY'),'DD-MM-YYYY');&lt;BR /&gt;Let vOpenDate2 = Date(DATE#(vOpening_Date,'DD-MM-YYYY'),'DD-MM-YYYY');&lt;BR /&gt;Let vCounter = $(MonthDiff(vOpenDate2, vCloseDate3));&lt;BR /&gt;&lt;BR /&gt;Let vMonth = Peek('Opening_Date', $(i), 'AllOutlets');&lt;BR /&gt;&lt;BR /&gt;for j = 0 to ($(vCounter)-1)&lt;BR /&gt;&lt;BR /&gt;[MonthTableTemp]:&lt;BR /&gt;Load&lt;BR /&gt;OutletID,&lt;BR /&gt;City,&lt;BR /&gt;Province,&lt;BR /&gt;Region,&lt;BR /&gt;Distributor,&lt;BR /&gt;Opening_Date,&lt;BR /&gt;year(Opening_Date) as OpeningYear,&lt;BR /&gt;Start_Date,&lt;BR /&gt;Closing_Date,&lt;BR /&gt;year(Closing_Date) as ClosingYear,&lt;BR /&gt;MonthlyOutletRental,&lt;BR /&gt;"OutletSize(Sq meter)",&lt;BR /&gt;"# of shop assistants",&lt;BR /&gt;PayrollCost,&lt;BR /&gt;if(($(j)+1) &amp;gt; 24, 'Month 24+', 'Month'&amp;amp;($(j)+1)) as MonthNum,&lt;BR /&gt;date(date#('$(vMonth)','DD-MM-YYYY'),'DD-MM-YYYY') as MonthDate ,&lt;BR /&gt;date(Monthend(date#('$(vMonth)','DD-MM-YYYY')),'MMM YYYY') as MonthDateF,&lt;BR /&gt;year(date(date#('$(vMonth)','DD-MM-YYYY'),'DD-MM-YYYY')) as Year,&lt;BR /&gt;if(($(j)+1) &amp;gt; 0 and ($(j)+1) &amp;lt;=12, 'Outlet 12 Months',&lt;BR /&gt;if(($(j)+1) &amp;gt; 12 and ($(j)+1) &amp;lt;= 24, 'Outlet 13-24 Months',&lt;BR /&gt;if(($(j)+1) &amp;gt; 24 and ($(j)+1) &amp;lt;= 36, 'Outlet 25-36 Months',&lt;BR /&gt;if(($(j)+1) &amp;gt; 36 and ($(j)+1) &amp;lt;= 48, 'Outlet 37-48 Months',&lt;BR /&gt;if(($(j)+1) &amp;gt; 48 and ($(j)+1) &amp;lt;= 60, 'Outlet 49-60 Months',&lt;BR /&gt;if(($(j)+1) &amp;gt; 60 and ($(j)+1) &amp;lt;= 72, 'Outlet 61-72 Months',&lt;BR /&gt;if(($(j)+1) &amp;gt; 72 and ($(j)+1) &amp;lt;= 84, 'Outlet 73-84 Months',&lt;BR /&gt;if(($(j)+1) &amp;gt; 84 and ($(j)+1) &amp;lt;= 96, 'Outlet 85-96 Months',&lt;BR /&gt;if(($(j)+1) &amp;gt; 96 and ($(j)+1) &amp;lt;= 108, 'Outlet 97-108 Months',&lt;BR /&gt;if(($(j)+1) &amp;gt; 108, 'Outlet 108+ Months')))))))))) as YearNum,&lt;BR /&gt;1 as OpenCount,&lt;BR /&gt;if('$(vMonth)' = '$(vClosing_Date)',1,0) as CloseCount,&lt;BR /&gt;if($(j) = 0, 1,&lt;BR /&gt;if('$(vMonth)' = '$(vClosing_Date)',-1,0)) as OpenCloseCount,&lt;BR /&gt;if($(j) = 0, year(Opening_Date)&amp;amp;'0',&lt;BR /&gt;if('$(vMonth)' = '$(vClosing_Date)',year(Opening_Date)&amp;amp;year(Closing_Date),year(Opening_Date))) as YearConcat&lt;BR /&gt;Resident AllOutlets&lt;BR /&gt;where OutletID = '$(vOutletID)'&lt;BR /&gt;and City = '$(vCity)'&lt;BR /&gt;and Region = '$(vRegion)'&lt;BR /&gt;and Opening_Date = '$(vOpening_Date)';&lt;BR /&gt;&lt;BR /&gt;vMonth = Date(MonthEnd(Date(AddMonths(vMonth,1),'DD-MM-YYYY')),'DD-MM-YYYY');&lt;BR /&gt;&lt;BR /&gt;Next j;&lt;BR /&gt;Next i;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Aug 2020 12:33:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/using-for-next-loop-taking-loading-time-6-hrs/m-p/1738809#M56479</guid>
      <dc:creator>Omkarsv2891</dc:creator>
      <dc:date>2020-08-26T12:33:18Z</dc:date>
    </item>
    <item>
      <title>Re: using for next loop taking loading time 6 hrs</title>
      <link>https://community.qlik.com/t5/App-Development/using-for-next-loop-taking-loading-time-6-hrs/m-p/1738816#M56481</link>
      <description>&lt;P&gt;It will be better to explain the requirement so that we can suggest the better option to achieve the same&lt;/P&gt;</description>
      <pubDate>Wed, 26 Aug 2020 12:42:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/using-for-next-loop-taking-loading-time-6-hrs/m-p/1738816#M56481</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2020-08-26T12:42:29Z</dc:date>
    </item>
    <item>
      <title>Re: using for next loop taking loading time 6 hrs</title>
      <link>https://community.qlik.com/t5/App-Development/using-for-next-loop-taking-loading-time-6-hrs/m-p/1738863#M56492</link>
      <description>&lt;P&gt;I think it's a great example of how it should &lt;STRONG&gt;not&lt;/STRONG&gt; be done ... Even with small datasets it will run quite long times ...&lt;/P&gt;&lt;P&gt;The reason for it is you pick each single record from your source within an outside-loop, nest then another outside-loop to create multiple additionally records in regard to the periods and load then from the source with multiple condition in a where-clause which means that each time the whole source is accessed to check the conditions and to load the data with your other transformations.&lt;/P&gt;&lt;P&gt;I think the same could be reached by using an inside-loop with while - simplified something in that way:&lt;/P&gt;&lt;P&gt;load date(floor(addmonths(Date1, iterno() -1))) as Date1, [further fields ...]&lt;BR /&gt;from source while iterno() &amp;lt;= MonthDiff(Date1, Date2);&lt;/P&gt;&lt;P&gt;- Marcus&lt;/P&gt;</description>
      <pubDate>Wed, 26 Aug 2020 14:30:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/using-for-next-loop-taking-loading-time-6-hrs/m-p/1738863#M56492</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2020-08-26T14:30:10Z</dc:date>
    </item>
  </channel>
</rss>

