<?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 Extracting single consecutive row in a loop from a loaded table in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Extracting-single-consecutive-row-in-a-loop-from-a-loaded-table/m-p/1681728#M51881</link>
    <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I have a table [HIRE TABLE] with PERSON_ID, HIRE_DATE and TERMINATION_DATE as columns.&lt;/P&gt;&lt;P&gt;I want to create a new table that has PERSON_ID, ACTIVE_DATE, ACTIVE_FLAG.&lt;BR /&gt;The ACTIVE_DATE is a date field that has dates starting from&amp;nbsp;HIRE_DATE till TERMINATION_DATE for each employee.&lt;BR /&gt;The&amp;nbsp;ACTIVE_FLAG will be accordingly be 1 for all employees.&lt;/P&gt;&lt;P&gt;What I am facing difficulty figuring out is how to have each&amp;nbsp;person with specific dates range starting from &lt;STRONG&gt;his&amp;nbsp;&lt;/STRONG&gt;HIRE_DATE till TERMINATION_DATE.&lt;/P&gt;&lt;P&gt;I hope it is understandable, and this is my attempt to solve it:&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;for each PERSON_ID in [Hire Date]&amp;nbsp; &amp;nbsp;//Looping for each ID in the table&lt;/P&gt;&lt;P&gt;StartAndEndDates:&amp;nbsp; // Table that will get the unique date for each person (Didn't work :s)&lt;BR /&gt;LOAD&lt;BR /&gt;HIRE_DATE AS FirstOrderDate,&lt;BR /&gt;TERMINATION_DATE_NEW AS LastOrderDate&lt;BR /&gt;RESIDENT [Hire Date];&lt;BR /&gt;//WHERE PERSON_ID = IterNo();&lt;/P&gt;&lt;P&gt;LET vFirstDate = NUM(PEEK('FirstOrderDate', 0, 'StartAndEndDates'));&lt;BR /&gt;LET vLastDate = NUM(PEEK('LastOrderDate', 0, 'StartAndEndDates'));&lt;/P&gt;&lt;P&gt;temp_GeneratedDates:&lt;BR /&gt;LOAD&lt;BR /&gt;PERSON_ID,&lt;BR /&gt;Date('$(vFirstDate)' + IterNo() - 1) AS ReferenceDate,&lt;BR /&gt;'1' as ACTIVE_FLAG&lt;BR /&gt;RESIDENT [Hire Date]&lt;BR /&gt;WHILE '$(vLastDate)' &amp;gt;= '$(vFirstDate)' + IterNo() + 1;&lt;/P&gt;&lt;P&gt;DROP TABLE StartAndEndDates;&lt;BR /&gt;next&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Mar 2020 15:02:50 GMT</pubDate>
    <dc:creator>HeshamKhja</dc:creator>
    <dc:date>2020-03-04T15:02:50Z</dc:date>
    <item>
      <title>Extracting single consecutive row in a loop from a loaded table</title>
      <link>https://community.qlik.com/t5/App-Development/Extracting-single-consecutive-row-in-a-loop-from-a-loaded-table/m-p/1681728#M51881</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I have a table [HIRE TABLE] with PERSON_ID, HIRE_DATE and TERMINATION_DATE as columns.&lt;/P&gt;&lt;P&gt;I want to create a new table that has PERSON_ID, ACTIVE_DATE, ACTIVE_FLAG.&lt;BR /&gt;The ACTIVE_DATE is a date field that has dates starting from&amp;nbsp;HIRE_DATE till TERMINATION_DATE for each employee.&lt;BR /&gt;The&amp;nbsp;ACTIVE_FLAG will be accordingly be 1 for all employees.&lt;/P&gt;&lt;P&gt;What I am facing difficulty figuring out is how to have each&amp;nbsp;person with specific dates range starting from &lt;STRONG&gt;his&amp;nbsp;&lt;/STRONG&gt;HIRE_DATE till TERMINATION_DATE.&lt;/P&gt;&lt;P&gt;I hope it is understandable, and this is my attempt to solve it:&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;for each PERSON_ID in [Hire Date]&amp;nbsp; &amp;nbsp;//Looping for each ID in the table&lt;/P&gt;&lt;P&gt;StartAndEndDates:&amp;nbsp; // Table that will get the unique date for each person (Didn't work :s)&lt;BR /&gt;LOAD&lt;BR /&gt;HIRE_DATE AS FirstOrderDate,&lt;BR /&gt;TERMINATION_DATE_NEW AS LastOrderDate&lt;BR /&gt;RESIDENT [Hire Date];&lt;BR /&gt;//WHERE PERSON_ID = IterNo();&lt;/P&gt;&lt;P&gt;LET vFirstDate = NUM(PEEK('FirstOrderDate', 0, 'StartAndEndDates'));&lt;BR /&gt;LET vLastDate = NUM(PEEK('LastOrderDate', 0, 'StartAndEndDates'));&lt;/P&gt;&lt;P&gt;temp_GeneratedDates:&lt;BR /&gt;LOAD&lt;BR /&gt;PERSON_ID,&lt;BR /&gt;Date('$(vFirstDate)' + IterNo() - 1) AS ReferenceDate,&lt;BR /&gt;'1' as ACTIVE_FLAG&lt;BR /&gt;RESIDENT [Hire Date]&lt;BR /&gt;WHILE '$(vLastDate)' &amp;gt;= '$(vFirstDate)' + IterNo() + 1;&lt;/P&gt;&lt;P&gt;DROP TABLE StartAndEndDates;&lt;BR /&gt;next&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 15:02:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Extracting-single-consecutive-row-in-a-loop-from-a-loaded-table/m-p/1681728#M51881</guid>
      <dc:creator>HeshamKhja</dc:creator>
      <dc:date>2020-03-04T15:02:50Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting single consecutive row in a loop from a loaded table</title>
      <link>https://community.qlik.com/t5/App-Development/Extracting-single-consecutive-row-in-a-loop-from-a-loaded-table/m-p/1681735#M51883</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;maybe something like this (file attached)?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 15:18:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Extracting-single-consecutive-row-in-a-loop-from-a-loaded-table/m-p/1681735#M51883</guid>
      <dc:creator>StarinieriG</dc:creator>
      <dc:date>2020-03-04T15:18:43Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting single consecutive row in a loop from a loaded table</title>
      <link>https://community.qlik.com/t5/App-Development/Extracting-single-consecutive-row-in-a-loop-from-a-loaded-table/m-p/1682005#M51923</link>
      <description>&lt;P&gt;Thank you so much.&lt;/P&gt;&lt;P&gt;Your solution helped me to come with the solution.&lt;/P&gt;&lt;P&gt;I ended with this:&lt;BR /&gt;-------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;// Iterating on each ID to extract the needed values (ID, HIRE_DATE, TERMINATION_DATE)&lt;BR /&gt;FOR p = 1 to NoOfRows('Hire Date')&lt;/P&gt;&lt;P&gt;// Creating Variables to hold the extracted needed values from HIRE DATE Table (ID, HIRE_DATE, TERMINATION_DATE)&lt;BR /&gt;// Using the PEEK() function to get the appropriate first and last date so we can generate the dates appropriately.&lt;BR /&gt;LET PERSON_ID = Peek('PERSON_ID', $(p)-1,'Hire Date');&lt;BR /&gt;LET vFirstDate = NUM(PEEK('HIRE_DATE', $(p)-1, 'Hire Date'));&lt;BR /&gt;LET vLastDate = NUM(PEEK('TERMINATION_DATE_NEW', $(p)-1, 'Hire Date'));&lt;/P&gt;&lt;P&gt;// Creating table [GeneratedDates] which we'll save the needed values in&lt;BR /&gt;GeneratedDates:&lt;BR /&gt;LOAD&lt;BR /&gt;$(PERSON_ID) AS PERSON_ID,&lt;BR /&gt;Date('$(vFirstDate)' + IterNo() - 1) AS ReferenceDate, //Incrementally generating dates&lt;BR /&gt;'1' as ACTIVE_FLAG&lt;BR /&gt;AutoGenerate 1 // Limit autogeneration to 1 time&lt;BR /&gt;WHILE '$(vLastDate)' &amp;gt;= '$(vFirstDate)' + IterNo() -1; //Generating dates only within the needed range&lt;/P&gt;&lt;P&gt;NEXT&lt;/P&gt;&lt;P&gt;-------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;Thanks a lot again!&lt;/P&gt;</description>
      <pubDate>Thu, 05 Mar 2020 10:50:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Extracting-single-consecutive-row-in-a-loop-from-a-loaded-table/m-p/1682005#M51923</guid>
      <dc:creator>HeshamKhja</dc:creator>
      <dc:date>2020-03-05T10:50:09Z</dc:date>
    </item>
  </channel>
</rss>

