<?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: Looping and generating new records in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Looping-and-generating-new-records/m-p/904061#M657437</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Swuehl&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I still needed to retain the records from the INPUT table so I've just concatenated the RESULT records to this original table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And I also removed the "-1" from the Iterno() functions as I don't want W7 replicating.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;P&gt;Adam&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 03 Jun 2015 10:52:57 GMT</pubDate>
    <dc:creator />
    <dc:date>2015-06-03T10:52:57Z</dc:date>
    <item>
      <title>Looping and generating new records</title>
      <link>https://community.qlik.com/t5/QlikView/Looping-and-generating-new-records/m-p/904059#M657435</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried a few ways of doing this but I'd like some advice on the simplest method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a table loaded in my QV script (see attached excel file).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For each unique PayrollNo there are 7 rows loaded with the Date field of each subsequent row being 1 calendar week after the previous. Different PayrollNo's can have different start dates but the same pattern of 6 subsequent weeks being loaded after remains.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I'd like to do is add additional records for each PayrollNo with the below rules...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Take the latest loaded date for each PayrollNo and generate additional weekly records (previous Date + 7) and stops when Date &amp;gt;= 31/12/2015. Then repeat for next PayrollNo.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;All other fields apart from Date should stay the same apart from TrainingWeek which should increase in +1 increments (W8, W9, W10). WeeklySalesTarget should always be 2 for all additional week records created.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can someone please assist / advise?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Adam&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 10:22:48 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Looping-and-generating-new-records/m-p/904059#M657435</guid>
      <dc:creator />
      <dc:date>2015-06-03T10:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: Looping and generating new records</title>
      <link>https://community.qlik.com/t5/QlikView/Looping-and-generating-new-records/m-p/904060#M657436</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Maybe something along this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;INPUT:&lt;/P&gt;&lt;P&gt;LOAD PayrollNo, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ResourceNameOrig, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pvTrainingStartDate, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pvTrainingFullyProductive, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TrainingWeek, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TrainingStage, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date, &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WeeklySalesTarget&lt;/P&gt;&lt;P&gt;FROM&lt;/P&gt;&lt;P&gt;[.\DateLoop.xlsx]&lt;/P&gt;&lt;P&gt;(ooxml, embedded labels, table is Sheet1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TMP:&lt;/P&gt;&lt;P&gt;NOCONCATENATE &lt;/P&gt;&lt;P&gt;LOAD PayrollNo,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Date(max(Date)) as Date,&lt;/P&gt;&lt;P&gt;&amp;nbsp; FirstSortedValue(ResourceNameOrig, -Date) as ResourceNameOrig,&lt;/P&gt;&lt;P&gt;&amp;nbsp; FirstSortedValue(pvTrainingStartDate, -Date) as pvTrainingStartDate,&lt;/P&gt;&lt;P&gt;&amp;nbsp; FirstSortedValue(pvTrainingFullyProductive, -Date) as pvTrainingFullyProductive,&lt;/P&gt;&lt;P&gt;&amp;nbsp; mid(FirstSortedValue(TrainingWeek, -Date),2) as TrainingWeek,&lt;/P&gt;&lt;P&gt;&amp;nbsp; FirstSortedValue(TrainingStage, -Date) as TrainingStage,&lt;/P&gt;&lt;P&gt;&amp;nbsp; FirstSortedValue(WeeklySalesTarget, -Date) as WeeklySalesTarget&lt;/P&gt;&lt;P&gt;RESIDENT INPUT&lt;/P&gt;&lt;P&gt;GROUP BY PayrollNo&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;DROP TABLE INPUT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;RESULT:&lt;/P&gt;&lt;P&gt;NOCONCATENATE&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;&amp;nbsp; PayrollNo,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Date(Date+(iterno()-1)*7) as Date,&lt;/P&gt;&lt;P&gt;&amp;nbsp; ResourceNameOrig,&lt;/P&gt;&lt;P&gt;&amp;nbsp; pvTrainingStartDate,&lt;/P&gt;&lt;P&gt;&amp;nbsp; pvTrainingFullyProductive,&lt;/P&gt;&lt;P&gt;&amp;nbsp; 'W' &amp;amp; (TrainingWeek+iterno()-1) as TrainingWeek,&lt;/P&gt;&lt;P&gt;&amp;nbsp; TrainingStage,&lt;/P&gt;&lt;P&gt;&amp;nbsp; WeeklySalesTarget&lt;/P&gt;&lt;P&gt;RESIDENT TMP&lt;/P&gt;&lt;P&gt;WHILE Date+(iterno()-1)*7 &amp;lt; MakeDate(2015,12,31);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;drop table TMP;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 10:37:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Looping-and-generating-new-records/m-p/904060#M657436</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2015-06-03T10:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: Looping and generating new records</title>
      <link>https://community.qlik.com/t5/QlikView/Looping-and-generating-new-records/m-p/904061#M657437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Swuehl&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I still needed to retain the records from the INPUT table so I've just concatenated the RESULT records to this original table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And I also removed the "-1" from the Iterno() functions as I don't want W7 replicating.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;&lt;P&gt;Adam&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 10:52:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Looping-and-generating-new-records/m-p/904061#M657437</guid>
      <dc:creator />
      <dc:date>2015-06-03T10:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: Looping and generating new records</title>
      <link>https://community.qlik.com/t5/QlikView/Looping-and-generating-new-records/m-p/904062#M657438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Adam&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use a While loop for this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Find the latest 'Date' for each PayrollNo&lt;/P&gt;&lt;P&gt;2. Use a While clause to generate each week between the latest 'Date' and the end date you have specified&lt;/P&gt;&lt;P&gt;3. Concatenate the rows from 2. on to the original table&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LatestDate:&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;&amp;nbsp; PayrollNo&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,ResourceNameOrig&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,pvTrainingStartDate&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,pvTrainingFullyProductive&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,TrainingStage&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,Max(Right(TrainingWeek,1)) as MaxTrainingWeek&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,Max(Date) as MaxDate&lt;/P&gt;&lt;P&gt;Resident&lt;/P&gt;&lt;P&gt;&amp;nbsp; DateLoopTable&lt;/P&gt;&lt;P&gt;Group By&lt;/P&gt;&lt;P&gt;&amp;nbsp; PayrollNo&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,ResourceNameOrig&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,pvTrainingStartDate&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,pvTrainingFullyProductive&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,TrainingStage&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 vEndDate = MakeDate(2015,12,31);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;RowsToConcatenate:&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;&amp;nbsp; PayrollNo&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,ResourceNameOrig&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,pvTrainingStartDate&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,pvTrainingFullyProductive&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,TrainingStage&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,'W' &amp;amp; MaxTrainingWeek+IterNo() as TrainingWeek&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,MaxDate+(IterNo()*7) as Date&lt;/P&gt;&lt;P&gt;Resident&lt;/P&gt;&lt;P&gt;&amp;nbsp; LatestDate&lt;/P&gt;&lt;P&gt;While&lt;/P&gt;&lt;P&gt;&amp;nbsp; MaxDate+(IterNo()*7)&amp;lt;=$(vEndDate)&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DROP Table LatestDate;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Concatenate(DateLoopTable)&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;&amp;nbsp; PayrollNo&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,ResourceNameOrig&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,pvTrainingStartDate&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,pvTrainingFullyProductive&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,TrainingStage&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,TrainingWeek&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,Date&lt;/P&gt;&lt;P&gt;&amp;nbsp; ,0 as WeeklySalesTarget&amp;nbsp; // Or just leave as Null&lt;/P&gt;&lt;P&gt;Resident&lt;/P&gt;&lt;P&gt;&amp;nbsp; RowsToConcatenate&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DROP Table RowsToConcatenate;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 10:53:42 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Looping-and-generating-new-records/m-p/904062#M657438</guid>
      <dc:creator />
      <dc:date>2015-06-03T10:53:42Z</dc:date>
    </item>
  </channel>
</rss>

