<?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: LOAD new field using set analysis in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/LOAD-new-field-using-set-analysis/m-p/4197#M790701</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;May be like attached&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.PNG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/190755_Capture.PNG" style="height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;Expression used&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;If([Start Date]=Date(Max(TOTAL &amp;lt;Prim_key&amp;gt; [Start Date])),Date([last date]),Date(Below(TOTAL [Start Date])-1))&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 20 Jan 2018 08:42:49 GMT</pubDate>
    <dc:creator>Anil_Babu_Samineni</dc:creator>
    <dc:date>2018-01-20T08:42:49Z</dc:date>
    <item>
      <title>LOAD new field using set analysis</title>
      <link>https://community.qlik.com/t5/QlikView/LOAD-new-field-using-set-analysis/m-p/4196#M790698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to insert a new field via the LOAD script called "End Date". This is the initial table:&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="149" style="border: 1px solid rgb(0, 0, 0); width: 319px; height: 150px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Prim_key&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;last_date&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Start Date&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;10001&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;3/31/2019&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4/1/2016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;10001&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;3/31/2019&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4/1/2017&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;10001&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;3/31/2019&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4/1/2018&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;10002&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;12/31/2020&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1/1/2016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;10002&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;12/31/2020&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1/1/2018&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;End Date would be defined as follows:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;For each row, get the MIN Start Date (for particular Prim_key) that is greater than the Start Date of that active row. For example for the first row, Start Date is 4/1/2016. The values for all Start Date for Prim_key=10001 is 4/1/2016, 4/1/2017, 4/1/2018. The MIN out of all those values greater than the Start Date of the active row (4/1/2016) is 4/1/2017.&lt;/LI&gt;&lt;LI&gt;Then subtract this value by 1. Using same example, the value for End Date for the first row would be 4/1/2017 minus 1 = 3/31/2017.&lt;/LI&gt;&lt;LI&gt;IF there is no MIN Start (for particular Prim_key) that is greater than the Start Date of that row (another way of saying this is IF Start Date of current row = MAX Start Date for that Prim_key) then the value for End Date would be equal to last_date. So for example in the 3rd row, since there is no MIN Start Date for Prim_key=10001 greater than 4/1/2018 then End Date is equal to last_date, which is 3/3/1/2019.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am having a hard time using set analysis to properly implement this in load script so that it is restricting the calculation to only within the set of values for a particular Prim_key as opposed to getting the min values in the entire table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Final loaded table should look like this:&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="149" style="border: 1px solid #000000; width: 319px; height: 150px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Prim_key&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;last_date&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Start Date&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;End Date&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;10001&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;3/31/2019&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4/1/2016&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;3/31/2017&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;10001&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;3/31/2019&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4/1/2017&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;3/31/2018&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;10001&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;3/31/2019&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4/1/2018&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;3/31/2019&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;10002&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;12/31/2020&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1/1/2016&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;12/31/2017&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;10002&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;12/31/2020&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1/1/2018&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;12/31/2020&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2020 16:16:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/LOAD-new-field-using-set-analysis/m-p/4196#M790698</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-11-25T16:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: LOAD new field using set analysis</title>
      <link>https://community.qlik.com/t5/QlikView/LOAD-new-field-using-set-analysis/m-p/4197#M790701</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;May be like attached&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.PNG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/190755_Capture.PNG" style="height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;Expression used&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;If([Start Date]=Date(Max(TOTAL &amp;lt;Prim_key&amp;gt; [Start Date])),Date([last date]),Date(Below(TOTAL [Start Date])-1))&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Jan 2018 08:42:49 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/LOAD-new-field-using-set-analysis/m-p/4197#M790701</guid>
      <dc:creator>Anil_Babu_Samineni</dc:creator>
      <dc:date>2018-01-20T08:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: LOAD new field using set analysis</title>
      <link>https://community.qlik.com/t5/QlikView/LOAD-new-field-using-set-analysis/m-p/4198#M790705</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; font-size: 13px;"&gt;I'm trying to insert a new field via the LOAD script called "End Date".&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you want in load script&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Table:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;LOAD * INLINE [&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Prim_key, Start Date, last date&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 100, 4/1/2016, 3/31/2019&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 100, 4/1/2017, 3/31/2019&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 100, 4/1/2018, 3/31/2019&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 200, 1/1/2016, 12/31/2020&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 200, 1/1/2018, 12/31/2020&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;];&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Table2:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;LOAD&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;*,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;IF(Prim_key = Peek('Prim_key'), Date(Peek('Start Date')-1), [last date]) as [End Date] &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Resident Table&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Order By Prim_key, [Start Date] desc;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;DROP Table Table;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;IMG alt="1.png" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/190761_1.png" style="height: auto; width: auto;" /&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Jan 2018 11:25:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/LOAD-new-field-using-set-analysis/m-p/4198#M790705</guid>
      <dc:creator>maxgro</dc:creator>
      <dc:date>2018-01-20T11:25:10Z</dc:date>
    </item>
  </channel>
</rss>

