<?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: Qlikview ETL Query - How to create additional rows based on input table. in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Qlikview-ETL-Query-How-to-create-additional-rows-based-on-input/m-p/276130#M708047</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can use iterNo() to generate records.&lt;/P&gt;&lt;P&gt;Below example creates one record for each date between start and end and then aggregates to month. Note that it is just one load statement having 4 preceding load stages (read from bottom up).&lt;/P&gt;&lt;P&gt;I personally would leave the facts at date basis for better analytics (w/o aggregation in script), but since you asked...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code"&gt;&lt;P&gt;Veh_service:&lt;/P&gt;&lt;P&gt;LOAD // aggregate&lt;/P&gt;&lt;P&gt;Veh_id,&lt;/P&gt;&lt;P&gt;Year_month,&lt;/P&gt;&lt;P&gt;sum(Earned_Days) as Earned_Days,&lt;/P&gt;&lt;P&gt;sum(Earned_Premium) as Earned_Premium&lt;/P&gt;&lt;P&gt;Group By Veh_id, Year_month&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;LOAD // add month dimension&lt;/P&gt;&lt;P&gt;*,&lt;/P&gt;&lt;P&gt;text(Date(Date,'YYYY-MM')) as Year_month&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;LOAD // create a record for each date:&lt;/P&gt;&lt;P&gt;Veh_id,&lt;/P&gt;&lt;P&gt;Premium / (Vehicle_End_Date - Vehicle_Start_Date) as Earned_Premium,&lt;/P&gt;&lt;P&gt;1 as Earned_Days,&lt;/P&gt;&lt;P&gt;date(Vehicle_Start_Date+(iterNo()-1)) as Date&lt;/P&gt;&lt;P&gt;WHILE iterNo() &amp;lt;= Vehicle_End_Date - Vehicle_Start_Date + 1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;LOAD // just to convert the date strings&lt;/P&gt;&lt;P&gt;Veh_id,&lt;/P&gt;&lt;P&gt;Date#(Vehicle_Start_Date,'DD-MMM-YYYY') as Vehicle_Start_Date,&lt;/P&gt;&lt;P&gt;Date#(Vehicle_End_Date,'DD-MMM-YYYY') as Vehicle_End_Date,&lt;/P&gt;&lt;P&gt;Premium&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;LOAD * INLINE [&lt;/P&gt;&lt;P&gt;Veh_id, Vehicle_Start_Date, Vehicle_End_Date, Premium&lt;/P&gt;&lt;P&gt;120, 15-dec-2011, 14-dec-2012, 250&lt;/P&gt;&lt;P&gt;121, 01-jan-2012, 31-dec-2012, 300&lt;/P&gt;&lt;P&gt;];&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 03 Dec 2011 22:27:07 GMT</pubDate>
    <dc:creator>tanelry</dc:creator>
    <dc:date>2011-12-03T22:27:07Z</dc:date>
    <item>
      <title>Qlikview ETL Query - How to create additional rows based on input table.</title>
      <link>https://community.qlik.com/t5/QlikView/Qlikview-ETL-Query-How-to-create-additional-rows-based-on-input/m-p/276129#M708046</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hii All, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am new to qlikview and am not familiar with the ETL process in Qlikview.&amp;nbsp; I have a query on the Data Transformation aspects of Qlikview. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a table that have the following fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Veh_id, Vehicle_Start_Date, Vehicle_End_Date, Premium&lt;/P&gt;&lt;P&gt;120, 15-dec-2011, 14-dec-2012, 250&lt;/P&gt;&lt;P&gt;121, 01-jan-2012, 31-dec-2012, 300&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;During the data load process, I want to create another table that stores the following information&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Year_month, veh_id, Earned_Days, Earned_Premium&lt;/P&gt;&lt;P&gt;2011-12, 120, 16, 11&lt;/P&gt;&lt;P&gt;2012-01, 120, 31, 21&lt;/P&gt;&lt;P&gt;2012-02, 120 ,29, 20&lt;/P&gt;&lt;P&gt;.....&lt;/P&gt;&lt;P&gt;2012-01,121,31, 25&lt;/P&gt;&lt;P&gt;2012-01,121,29, 24&lt;/P&gt;&lt;P&gt;.....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This table stores the number of days a vehicle was active during the month along with the premium earned during this period.&lt;/P&gt;&lt;P&gt;So for each record in the base table, there can be around 12 records to be created in the new table.&amp;nbsp; One record for each month a vehicle was active. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you guys pls let me know how I should script the creation of a new table with this information during the load process.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Jibu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 03 Dec 2011 05:11:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Qlikview-ETL-Query-How-to-create-additional-rows-based-on-input/m-p/276129#M708046</guid>
      <dc:creator />
      <dc:date>2011-12-03T05:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: Qlikview ETL Query - How to create additional rows based on input table.</title>
      <link>https://community.qlik.com/t5/QlikView/Qlikview-ETL-Query-How-to-create-additional-rows-based-on-input/m-p/276130#M708047</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can use iterNo() to generate records.&lt;/P&gt;&lt;P&gt;Below example creates one record for each date between start and end and then aggregates to month. Note that it is just one load statement having 4 preceding load stages (read from bottom up).&lt;/P&gt;&lt;P&gt;I personally would leave the facts at date basis for better analytics (w/o aggregation in script), but since you asked...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code"&gt;&lt;P&gt;Veh_service:&lt;/P&gt;&lt;P&gt;LOAD // aggregate&lt;/P&gt;&lt;P&gt;Veh_id,&lt;/P&gt;&lt;P&gt;Year_month,&lt;/P&gt;&lt;P&gt;sum(Earned_Days) as Earned_Days,&lt;/P&gt;&lt;P&gt;sum(Earned_Premium) as Earned_Premium&lt;/P&gt;&lt;P&gt;Group By Veh_id, Year_month&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;LOAD // add month dimension&lt;/P&gt;&lt;P&gt;*,&lt;/P&gt;&lt;P&gt;text(Date(Date,'YYYY-MM')) as Year_month&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;LOAD // create a record for each date:&lt;/P&gt;&lt;P&gt;Veh_id,&lt;/P&gt;&lt;P&gt;Premium / (Vehicle_End_Date - Vehicle_Start_Date) as Earned_Premium,&lt;/P&gt;&lt;P&gt;1 as Earned_Days,&lt;/P&gt;&lt;P&gt;date(Vehicle_Start_Date+(iterNo()-1)) as Date&lt;/P&gt;&lt;P&gt;WHILE iterNo() &amp;lt;= Vehicle_End_Date - Vehicle_Start_Date + 1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;LOAD // just to convert the date strings&lt;/P&gt;&lt;P&gt;Veh_id,&lt;/P&gt;&lt;P&gt;Date#(Vehicle_Start_Date,'DD-MMM-YYYY') as Vehicle_Start_Date,&lt;/P&gt;&lt;P&gt;Date#(Vehicle_End_Date,'DD-MMM-YYYY') as Vehicle_End_Date,&lt;/P&gt;&lt;P&gt;Premium&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;LOAD * INLINE [&lt;/P&gt;&lt;P&gt;Veh_id, Vehicle_Start_Date, Vehicle_End_Date, Premium&lt;/P&gt;&lt;P&gt;120, 15-dec-2011, 14-dec-2012, 250&lt;/P&gt;&lt;P&gt;121, 01-jan-2012, 31-dec-2012, 300&lt;/P&gt;&lt;P&gt;];&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 03 Dec 2011 22:27:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Qlikview-ETL-Query-How-to-create-additional-rows-based-on-input/m-p/276130#M708047</guid>
      <dc:creator>tanelry</dc:creator>
      <dc:date>2011-12-03T22:27:07Z</dc:date>
    </item>
  </channel>
</rss>

