<?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 Autogenerate Loop inside loop in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Autogenerate-Loop-inside-loop/m-p/24404#M604869</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;&lt;SPAN style="font-size: 10pt;"&gt;I'm trying to run the below script&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The purpose is to create dates records&lt;SPAN style="font-size: 13.3333px;"&gt;(Autogenerated date + 1 for g records)&lt;/SPAN&gt; per SKU based on avg. dates per Category&lt;/P&gt;&lt;P&gt;what am I doing wrong?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;InventoryTemp_Gen:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Load DISTINCT ROWNO() AS SKUid,SKU,Category Resident Item_Master_Data&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Where LEFT(SKU,3)='FI-';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;left join &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Load * Resident Temp_Inv_Dates_3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Left JOIN &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Load Category,AVG.Inv_Date as Inv_Date From qvd/avgnvtable.QVD(qvd);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;drop table Temp_Inv_Dates_3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Store InventoryTemp_Gen into qvd/InventoryTemp_Gen.QVD; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;let vSKUsInv = FieldValuecount(FieldName(2,'InventoryTemp_Gen'));&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;for i = 1 to vSKUsInv&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;let vSKUsInvGenName = peek('SKU',$(i),'InventoryTemp_Gen'); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;let vSKUsInvGenCatName = peek('Category',$(i),'InventoryTemp_Gen'); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;let vSKUsInvGen = peek('Avg.#Inv_Date',$(i),'InventoryTemp_Gen'); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;let vSKUsInv_Date = peek('Inv_Date',$(i),'InventoryTemp_Gen'); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;If vSKUsInv&amp;lt;0 THEN&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;for g = 1 to vSKUsInvGen&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;let vSKUsInv_DateGen = date(num(vSKUsInv_Date)+g);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;InventoryTemp:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Load '$(vSKUsInvGenName)' as SKU,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;'$(vSKUsInvGenCatName)' as Category,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;'$(vSKUsInv_DateGen)' as Inv_Date&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;AutoGenerate 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;next g&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;next i&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;store InventoryTemp into qvd/InventoryTemp_Gen2.QVD;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;SPAN style="color: #000000;"&gt;Thank you&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 14 Jun 2018 06:18:16 GMT</pubDate>
    <dc:creator>seWork</dc:creator>
    <dc:date>2018-06-14T06:18:16Z</dc:date>
    <item>
      <title>Autogenerate Loop inside loop</title>
      <link>https://community.qlik.com/t5/QlikView/Autogenerate-Loop-inside-loop/m-p/24404#M604869</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;&lt;SPAN style="font-size: 10pt;"&gt;I'm trying to run the below script&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The purpose is to create dates records&lt;SPAN style="font-size: 13.3333px;"&gt;(Autogenerated date + 1 for g records)&lt;/SPAN&gt; per SKU based on avg. dates per Category&lt;/P&gt;&lt;P&gt;what am I doing wrong?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;InventoryTemp_Gen:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Load DISTINCT ROWNO() AS SKUid,SKU,Category Resident Item_Master_Data&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Where LEFT(SKU,3)='FI-';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;left join &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Load * Resident Temp_Inv_Dates_3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Left JOIN &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Load Category,AVG.Inv_Date as Inv_Date From qvd/avgnvtable.QVD(qvd);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;drop table Temp_Inv_Dates_3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Store InventoryTemp_Gen into qvd/InventoryTemp_Gen.QVD; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;let vSKUsInv = FieldValuecount(FieldName(2,'InventoryTemp_Gen'));&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;for i = 1 to vSKUsInv&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;let vSKUsInvGenName = peek('SKU',$(i),'InventoryTemp_Gen'); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;let vSKUsInvGenCatName = peek('Category',$(i),'InventoryTemp_Gen'); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;let vSKUsInvGen = peek('Avg.#Inv_Date',$(i),'InventoryTemp_Gen'); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;let vSKUsInv_Date = peek('Inv_Date',$(i),'InventoryTemp_Gen'); &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;If vSKUsInv&amp;lt;0 THEN&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;for g = 1 to vSKUsInvGen&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;let vSKUsInv_DateGen = date(num(vSKUsInv_Date)+g);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;InventoryTemp:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;Load '$(vSKUsInvGenName)' as SKU,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;'$(vSKUsInvGenCatName)' as Category,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;'$(vSKUsInv_DateGen)' as Inv_Date&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;AutoGenerate 1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;next g&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;next i&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;store InventoryTemp into qvd/InventoryTemp_Gen2.QVD;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&lt;SPAN style="color: #000000;"&gt;Thank you&lt;/SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jun 2018 06:18:16 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Autogenerate-Loop-inside-loop/m-p/24404#M604869</guid>
      <dc:creator>seWork</dc:creator>
      <dc:date>2018-06-14T06:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: Autogenerate Loop inside loop</title>
      <link>https://community.qlik.com/t5/QlikView/Autogenerate-Loop-inside-loop/m-p/24405#M604870</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;FieldValueCount applies to a field. I think you are attempting to use it for a table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;let vSKUsInv = FieldValuecount(FieldName(2,'&lt;STRONG&gt;InventoryTemp_Gen&lt;/STRONG&gt;'));&amp;nbsp;&amp;nbsp; &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This should probably be &lt;EM&gt;NoOfRows('&lt;STRONG&gt;InventoryTemp_Gen&lt;/STRONG&gt;')&lt;/EM&gt;. Or use &lt;EM&gt;QvdNoOfRecords('...QVD file name...').&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jun 2018 06:27:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Autogenerate-Loop-inside-loop/m-p/24405#M604870</guid>
      <dc:creator>jonathandienst</dc:creator>
      <dc:date>2018-06-14T06:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Autogenerate Loop inside loop</title>
      <link>https://community.qlik.com/t5/QlikView/Autogenerate-Loop-inside-loop/m-p/24406#M604871</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The &lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #666666;"&gt;vSKUsInv&amp;nbsp; var is ok for both of the options and I'm getting the right value for it&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #666666;"&gt;The problem is that during the run with both of the options I'm receiving an error regarding the loop vars'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica','sans-serif'; color: #666666;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Semantic error&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;The control statement is not correctly matched with its corresponding start statement &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt;next i&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #666666; font-family: Helvetica, sans-serif; font-size: 10.5pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #666666; font-family: Helvetica, sans-serif; font-size: 10.5pt;"&gt;and the result is only 1 row with 1 SKU instead of "g" rows per SKU("i" SKUS)&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jun 2018 07:06:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Autogenerate-Loop-inside-loop/m-p/24406#M604871</guid>
      <dc:creator>seWork</dc:creator>
      <dc:date>2018-06-14T07:06:27Z</dc:date>
    </item>
    <item>
      <title>Re: Autogenerate Loop inside loop</title>
      <link>https://community.qlik.com/t5/QlikView/Autogenerate-Loop-inside-loop/m-p/24407#M604872</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My full script is &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm getting the same error for various of loops&lt;/P&gt;&lt;P&gt;"&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;Semantic error&lt;/P&gt;&lt;P style="font-size: 13px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;The control statement is not correctly matched with its corresponding start statement &lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 10pt; font-family: inherit;"&gt;next %"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Inventory:&lt;/P&gt;&lt;P&gt;LOAD &lt;/P&gt;&lt;P&gt;Distinct $(vInventory_Calc)&lt;/P&gt;&lt;P&gt;FROM&lt;/P&gt;&lt;P&gt;Inventory.qvd&lt;/P&gt;&lt;P&gt;(qvd)&lt;/P&gt;&lt;P&gt;Where Inv_Pallets&amp;gt;0&lt;/P&gt;&lt;P&gt;and not isnull(Inv_Pallets);&lt;/P&gt;&lt;P&gt;RENAME Field Inv_Date to old.Inv_Date;&lt;/P&gt;&lt;P&gt;Left join&lt;/P&gt;&lt;P&gt;Load Distinct(old.Inv_Date) as old.Inv_Date,date(old.Inv_Date) as Inv_Date Resident Inventory;&lt;/P&gt;&lt;P&gt;drop Field old.Inv_Date;&lt;/P&gt;&lt;P&gt;Left join&lt;/P&gt;&lt;P&gt;Load Distinct SKU,Category Resident Item_Master_Data;&lt;/P&gt;&lt;P&gt;store Inventory into qvd/Inventory.QVD;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;let vTablei = NoOfFields('Inventory');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;avgnvtable :&lt;/P&gt;&lt;P&gt;load distinct Category&amp;nbsp; resident Inventory;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FOR ia = 1 to vTablei&lt;/P&gt;&lt;P&gt;IF ia&amp;lt;vTablei THEN&lt;/P&gt;&lt;P&gt;let fname = FieldName(ia,'Inventory');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; inner join (avgnvtable) &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Load Category&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,if(isnum(maxString($(fname))),CEIL(Avg($(fname))),subfield(concat($(fname),'/'),'/',ceil(rand()*count($(fname))))) as AVG.$(fname)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Resident Inventory group by Category;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF fname = 'Category' THEN&lt;/P&gt;&lt;P&gt;drop Field AVG.Category;&lt;/P&gt;&lt;P&gt;ELSEIF fname ='SKU' THEN&lt;/P&gt;&lt;P&gt;drop Field AVG.SKU;&lt;/P&gt;&lt;P&gt;ELSE&lt;/P&gt;&lt;P&gt;ENDIF&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Next ia;&lt;/P&gt;&lt;P&gt;ELSE &lt;/P&gt;&lt;P&gt;EXIT FOR&lt;/P&gt;&lt;P&gt;ENDIF&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;RENAME Field AVG.Inv_Date TO old.AVG.Inv_Date;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Left Join(avgnvtable)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load distinct(old.AVG.Inv_Date) as old.AVG.Inv_Date,Date(old.AVG.Inv_Date) as AVG.Inv_Date Resident avgnvtable;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Drop Field old.AVG.Inv_Date From avgnvtable; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Store avgnvtable into qvd/avgnvtable.QVD;&lt;/P&gt;&lt;P&gt;Drop Table avgnvtable;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ELSE&lt;/P&gt;&lt;P&gt;end if&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Temp_Inv_Dates_1:&lt;/P&gt;&lt;P&gt;Load Distinct SKU,Category,COUNT(Inv_Date) as #Inv_Date Resident Inventory&lt;/P&gt;&lt;P&gt;Group by SKU,Category;&lt;/P&gt;&lt;P&gt;Store Temp_Inv_Dates_1 into qvd/Temp_Inv_Dates_1.QVD;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Temp_Inv_Dates_2:&lt;/P&gt;&lt;P&gt;Load Category,Count(SKU) as #SKU,SUM(#Inv_Date) as Total#Inv_Date Resident Temp_Inv_Dates_1&lt;/P&gt;&lt;P&gt;Group by Category;&lt;/P&gt;&lt;P&gt;DROP TABLE Temp_Inv_Dates_1;&lt;/P&gt;&lt;P&gt;Store Temp_Inv_Dates_2 into qvd/Temp_Inv_Dates_2.QVD;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Temp_Inv_Dates_3:&lt;/P&gt;&lt;P&gt;Load Category,CEIL(Total#Inv_Date/#SKU) as Avg.#Inv_Date Resident Temp_Inv_Dates_2;&lt;/P&gt;&lt;P&gt;DROP TABLE Temp_Inv_Dates_2;&lt;/P&gt;&lt;P&gt;Store Temp_Inv_Dates_3 into qvd/Temp_Inv_Dates_3.QVD;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;InventoryTemp_Gen:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load DISTINCT ROWNO() AS SKUid,SKU,Category Resident Item_Master_Data&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Where LEFT(SKU,3)='FI-';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;let vSKUsInv = FieldValuecount(FieldName(2,'InventoryTemp_Gen'))-1;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if vSKUsInv&amp;gt;=1 then&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;left join(InventoryTemp_Gen)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load * Resident Temp_Inv_Dates_3;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Left JOIN&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load Category,AVG.Inv_Date as Inv_Date From qvd/avgnvtable.QVD(qvd);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;drop table Temp_Inv_Dates_3;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Store InventoryTemp_Gen into qvd/InventoryTemp_Gen.QVD;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for d = 1 to vSKUsInv&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;let vSKUsInvGenName = peek('SKU',$(d),'InventoryTemp_Gen');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;let vSKUsInvGenCatName = peek('Category',$(d),'InventoryTemp_Gen');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;let vSKUsInvGen = peek('Avg.#Inv_Date',$(d),'InventoryTemp_Gen');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;let vSKUsInv_Date = peek('Inv_Date',$(d),'InventoryTemp_Gen');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for g = 1 to vSKUsInvGen&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;let vSKUsInv_DateGen = date(num(vSKUsInv_Date)+g);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;InventoryTemp:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load '$(vSKUsInvGenName)' as SKU,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;'$(vSKUsInvGenCatName)' as Category,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;'$(vSKUsInv_DateGen)' as Inv_Date&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AutoGenerate 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;next g;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;next d;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;store InventoryTemp into qvd/InventoryTemp_Gen2.QVD;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Left join&lt;/P&gt;&lt;P&gt;Load * From qvd/avgnvtable.QVD(qvd);&lt;/P&gt;&lt;P&gt;Drop Field AVG.Inv_Date from InventoryTemp;&lt;/P&gt;&lt;P&gt;let vTable = NoOfFields('InventoryTemp');&lt;/P&gt;&lt;P&gt;For i = 1 to vTable&lt;/P&gt;&lt;P&gt;let fname = FieldName(i,'InventoryTemp');&lt;/P&gt;&lt;P&gt;let Nfname = mid(fname,5,len(fname)-4);&lt;/P&gt;&lt;P&gt;If left(fname,4) = 'AVG.' THEN&lt;/P&gt;&lt;P&gt;RENAME Field $(fname) TO $(Nfname);&lt;/P&gt;&lt;P&gt;next i;&lt;/P&gt;&lt;P&gt;else&lt;/P&gt;&lt;P&gt;endif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;store InventoryTemp into qvd/InventoryTemp.QVD;&lt;/P&gt;&lt;P&gt;drop table InventoryTemp;&lt;/P&gt;&lt;P&gt;drop table InventoryTemp_Gen;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;else&lt;/P&gt;&lt;P&gt;endif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Inventory:&lt;/P&gt;&lt;P&gt;LOAD * ,SKU&amp;amp;'-'&amp;amp;Batch AS Rec_Inv_Key&lt;/P&gt;&lt;P&gt;FROM&lt;/P&gt;&lt;P&gt;qvd\Inventory.QVD&lt;/P&gt;&lt;P&gt;(qvd);&lt;/P&gt;&lt;P&gt;Concatenate&lt;/P&gt;&lt;P&gt;LOAD *,SKU&amp;amp;'-'&amp;amp;Batch AS Rec_Inv_Key &lt;/P&gt;&lt;P&gt;FROM qvd/InventoryTemp.QVD&lt;/P&gt;&lt;P&gt;(qvd);&lt;/P&gt;&lt;P&gt;drop Field Category from Inventory;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Inner JOIN(Inventory)&lt;/P&gt;&lt;P&gt;Load Distinct SKU,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Sum(Inv_Pallets) as Total_INV,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Count(DISTINCT Inv_Date) as N_Inv_Date,&lt;/P&gt;&lt;P&gt;&amp;nbsp; if(Sum(Inv_Pallets)/Count(DISTINCT Inv_Date)&amp;gt;=$(Inv_ABCD_AA),dual('AA',1),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(Sum(Inv_Pallets)/Count(DISTINCT Inv_Date)&amp;gt;=$(Inv_ABCD_A),dual('A',2),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(Sum(Inv_Pallets)/Count(DISTINCT Inv_Date)&amp;gt;=$(Inv_ABCD_B),dual('B',3),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(Sum(Inv_Pallets)/Count(DISTINCT Inv_Date)&amp;gt;=$(Inv_ABCD_C),dual('C',4),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(Sum(Inv_Pallets)/Count(DISTINCT Inv_Date)&amp;gt;=$(Inv_ABCD_D),dual('D',5),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(Sum(Inv_Pallets)/Count(DISTINCT Inv_Date)&amp;gt;=$(Inv_ABCD_E),dual('E',6),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(Sum(Inv_Pallets)/Count(DISTINCT Inv_Date)&amp;gt;=$(Inv_ABCD_F),dual('F',7),dual('G',8)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ))))))) AS Inv_ABCD&lt;/P&gt;&lt;P&gt;Resident Inventory&lt;/P&gt;&lt;P&gt;GROUP BY SKU;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jun 2018 10:27:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Autogenerate-Loop-inside-loop/m-p/24407#M604872</guid>
      <dc:creator>seWork</dc:creator>
      <dc:date>2018-06-14T10:27:04Z</dc:date>
    </item>
  </channel>
</rss>

