<?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 Script for load inline and row duplication with loop in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Script-for-load-inline-and-row-duplication-with-loop/m-p/1841281#M69685</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I'm trying to find a way to duplicate existing rows with an inline load statement. The result will help me calculating late deliveries for each week until the order has been fully shipped.&lt;/P&gt;&lt;P&gt;I've prepared a QVF sample to find the best solution with your kind support :&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="patricesalem_0-1633334512569.png" style="width: 558px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/63236i66E9B8D2B751EBB7/image-dimensions/558x107?v=v2" width="558" height="107" role="button" title="patricesalem_0-1633334512569.png" alt="patricesalem_0-1633334512569.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;ie : I would like the first line to be duplicated (thanks to an load * inline script) 5 times.&lt;BR /&gt;Each time, the line would be duplicated incrementing the To_be_delivered_on_week field by one.&lt;BR /&gt;The result would be for that line :&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="patricesalem_1-1633334653917.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/63237iBD1E1DCEB546E151/image-size/medium?v=v2&amp;amp;px=400" role="button" title="patricesalem_1-1633334653917.png" alt="patricesalem_1-1633334653917.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the attached QVF, I have created a set of records to be able to test your proposals:&lt;/P&gt;&lt;P&gt;[ORDER_DATA]:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;Order_Number, Part_Number, To_be_delivered_on_week, Delivered_on_week&lt;BR /&gt;123456,2500,30,35&lt;BR /&gt;123456,2600,30,34&lt;BR /&gt;123457,3500,33,37&lt;BR /&gt;123458,4000,37,37&lt;BR /&gt;];&lt;/P&gt;&lt;P&gt;Then the load * inline script I'm looking for would be concatenating its result with the above table...but I don't see how to write it.&lt;BR /&gt;&lt;BR /&gt;Any idea/input would be greatly appreciated.&lt;BR /&gt;Thanks&lt;BR /&gt;Pat&lt;BR /&gt;Qlik Sense Server May 2021&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 04 Oct 2021 08:11:04 GMT</pubDate>
    <dc:creator>patricesalem</dc:creator>
    <dc:date>2021-10-04T08:11:04Z</dc:date>
    <item>
      <title>Script for load inline and row duplication with loop</title>
      <link>https://community.qlik.com/t5/App-Development/Script-for-load-inline-and-row-duplication-with-loop/m-p/1841281#M69685</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I'm trying to find a way to duplicate existing rows with an inline load statement. The result will help me calculating late deliveries for each week until the order has been fully shipped.&lt;/P&gt;&lt;P&gt;I've prepared a QVF sample to find the best solution with your kind support :&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="patricesalem_0-1633334512569.png" style="width: 558px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/63236i66E9B8D2B751EBB7/image-dimensions/558x107?v=v2" width="558" height="107" role="button" title="patricesalem_0-1633334512569.png" alt="patricesalem_0-1633334512569.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;ie : I would like the first line to be duplicated (thanks to an load * inline script) 5 times.&lt;BR /&gt;Each time, the line would be duplicated incrementing the To_be_delivered_on_week field by one.&lt;BR /&gt;The result would be for that line :&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="patricesalem_1-1633334653917.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/63237iBD1E1DCEB546E151/image-size/medium?v=v2&amp;amp;px=400" role="button" title="patricesalem_1-1633334653917.png" alt="patricesalem_1-1633334653917.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the attached QVF, I have created a set of records to be able to test your proposals:&lt;/P&gt;&lt;P&gt;[ORDER_DATA]:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;Order_Number, Part_Number, To_be_delivered_on_week, Delivered_on_week&lt;BR /&gt;123456,2500,30,35&lt;BR /&gt;123456,2600,30,34&lt;BR /&gt;123457,3500,33,37&lt;BR /&gt;123458,4000,37,37&lt;BR /&gt;];&lt;/P&gt;&lt;P&gt;Then the load * inline script I'm looking for would be concatenating its result with the above table...but I don't see how to write it.&lt;BR /&gt;&lt;BR /&gt;Any idea/input would be greatly appreciated.&lt;BR /&gt;Thanks&lt;BR /&gt;Pat&lt;BR /&gt;Qlik Sense Server May 2021&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Oct 2021 08:11:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Script-for-load-inline-and-row-duplication-with-loop/m-p/1841281#M69685</guid>
      <dc:creator>patricesalem</dc:creator>
      <dc:date>2021-10-04T08:11:04Z</dc:date>
    </item>
    <item>
      <title>Re: Script for load inline and row duplication with loop</title>
      <link>https://community.qlik.com/t5/App-Development/Script-for-load-inline-and-row-duplication-with-loop/m-p/1841340#M69689</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;Thanks to another post (in &lt;A href="https://stackoverflow.com/questions/68233814/loops-through-months-in-qlik-sense" target="_self"&gt;stackoverflow&lt;/A&gt;), I have found the solution :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[ORDER_DATA]:
Load * Inline [
  ID, Order_Number, Order_Line_Number, To_be_delivered_on_week   , Delivered_on_week
  123456_10,123456,10,30,35
  123456_20,123456,20,30,34
  123457_35,123457,35,33,37
  123458_40,123458,40,37,37
  ];


TempTable:
Load
  distinct
  ID &amp;amp; '^' &amp;amp; Order_Number &amp;amp; '^' &amp;amp; Order_Line_Number &amp;amp; '^' &amp;amp; [To_be_delivered_on_week] &amp;amp; '^' &amp;amp; [Delivered_on_week] as Id_Weeks
Resident
  ORDER_DATA
;

// for each record in Id_Dates field
for i = 1 to FieldValueCount('Id_Weeks')
 
 // get the current iteration value
  let value = FieldValue('Id_Weeks', $(i));
  
  // extract the Id
  let currentId = SubField('$(value)', '^', 1);
  
  //Extract Order Number
  let currentOrder = SubField('$(value)', '^', 2);
  
  //Extract Order Line Number
  let currentLine = SubField('$(value)', '^', 3);
  
  
  // extract week to be delivered  
  let currentWeekStart = Num(SubField('$(value)', '^', 4));
  
  // extract week of delivery
  let currentWeekEnd = Num(SubField('$(value)', '^', 5));

  // autogenerate all weeks between the week to deliver and week of delivery
   // add the current Id value (this will link to the RawData table)
  ORDER_DATA_FINAL:
  LOAD
    '$(currentId)' as Id,
    '$(currentOrder)' as Order,
    '$(currentLine)' as Order_Line_Number,
    '$(currentWeekEnd)' as Week_of_Delivery,
    $(WeekStart) + IterNo() - 1 AS Due_Week_of_Delivery
  AUTOGENERATE (1)
  WHILE 
    $(currentWeekStart) + IterNo() -1 &amp;lt;= $(currentWeekEnd)
  ;

next

// we dont need this table anymore
Drop Table TempTable;
Drop Table ORDER_DATA;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It works exactly as expected. Feel free to let me know if there is a way to make it better (ie: for the duplication of 500K lines +)&lt;/P&gt;&lt;P&gt;Hope my solution will be used by others, stuck as I've been for a few days (before posting...)&lt;BR /&gt;Pat&lt;/P&gt;</description>
      <pubDate>Mon, 04 Oct 2021 09:52:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Script-for-load-inline-and-row-duplication-with-loop/m-p/1841340#M69689</guid>
      <dc:creator>patricesalem</dc:creator>
      <dc:date>2021-10-04T09:52:20Z</dc:date>
    </item>
  </channel>
</rss>

