<?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 find next value using script in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/find-next-value-using-script/m-p/272677#M102084</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Phil,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I understand your situation correctly it sounds as though you're most of the way there with the previous() function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm assuming that amoungst your data table you have fields that are something similar to an 'IncidentID' and 'AttendedTime', if so the following should get you started:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lets say the table you have is simply called 'Data' and have already loaded it in your script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Qualify *;&lt;/P&gt;&lt;P&gt;Data_2:&lt;/P&gt;&lt;P&gt;Load *,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(previous(IncidentID)=IncidentID,'Precursor','First/Final') as Indicator;&lt;/P&gt;&lt;P&gt;NoConcatenate Load&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *; // Your data fields&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;Resident Data Order By IncidentID Asc, AttendedTime Desc;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*I haven't checked that syntax but the principal is there (I use it in the wild).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Essentially what you're doing is grouping the incidents together then ordering them with the most recent AttendedTime at the top of each group - ie the last time they were seen; this can be derived by looking at the previous IncidentID; if it's different we must be looking at a final visit (of the one and only) of a seperate incident. Likewise if the row above has the same IncidentID then we must be looking at a precursor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also do the following to show how many visits there have been and the gap between first and last:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unqualify *;&lt;/P&gt;&lt;P&gt;Left Join (Data_2)&lt;/P&gt;&lt;P&gt;Load IncidentID,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count(IncidentID) as Visits,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; max(AttendedTime)-min(AttendedTime) as TotalTime;&lt;/P&gt;&lt;P&gt;Resident Data_2 Group By IncidentID;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As mentioned the syntax isn't checked so you may need to make some slight changes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any problems; post an example file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Matt - Visual Analytics Ltd&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 15 Aug 2011 15:09:59 GMT</pubDate>
    <dc:creator>matt_crowther</dc:creator>
    <dc:date>2011-08-15T15:09:59Z</dc:date>
    <item>
      <title>find next value using script</title>
      <link>https://community.qlik.com/t5/QlikView/find-next-value-using-script/m-p/272675#M102082</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a table showing peoples names and the date that thy were attended to. I am using the PREV statement in the script to look up the date difference between a previous incident and that incident. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What has been pointed out though is that users want to see if the incident resulted in a follow up attendance. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so instead of looking for all incidents which was the follow up, I need to know which incidents were the precursor to a follow up. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is this possible? And how would I do this? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Aug 2011 14:52:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/find-next-value-using-script/m-p/272675#M102082</guid>
      <dc:creator />
      <dc:date>2011-08-15T14:52:23Z</dc:date>
    </item>
    <item>
      <title>find next value using script</title>
      <link>https://community.qlik.com/t5/QlikView/find-next-value-using-script/m-p/272676#M102083</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you may want to have a look into the chapter 23.6 ( semantic tables) in the reference manual.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think you could use a semantic table to hold information for preceding / following visits.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You might also want to look into the presidents demo qvw.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps,&lt;/P&gt;&lt;P&gt;Stefan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Aug 2011 15:05:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/find-next-value-using-script/m-p/272676#M102083</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2011-08-15T15:05:07Z</dc:date>
    </item>
    <item>
      <title>find next value using script</title>
      <link>https://community.qlik.com/t5/QlikView/find-next-value-using-script/m-p/272677#M102084</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Phil,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I understand your situation correctly it sounds as though you're most of the way there with the previous() function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm assuming that amoungst your data table you have fields that are something similar to an 'IncidentID' and 'AttendedTime', if so the following should get you started:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lets say the table you have is simply called 'Data' and have already loaded it in your script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Qualify *;&lt;/P&gt;&lt;P&gt;Data_2:&lt;/P&gt;&lt;P&gt;Load *,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(previous(IncidentID)=IncidentID,'Precursor','First/Final') as Indicator;&lt;/P&gt;&lt;P&gt;NoConcatenate Load&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *; // Your data fields&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;Resident Data Order By IncidentID Asc, AttendedTime Desc;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*I haven't checked that syntax but the principal is there (I use it in the wild).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Essentially what you're doing is grouping the incidents together then ordering them with the most recent AttendedTime at the top of each group - ie the last time they were seen; this can be derived by looking at the previous IncidentID; if it's different we must be looking at a final visit (of the one and only) of a seperate incident. Likewise if the row above has the same IncidentID then we must be looking at a precursor.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can also do the following to show how many visits there have been and the gap between first and last:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unqualify *;&lt;/P&gt;&lt;P&gt;Left Join (Data_2)&lt;/P&gt;&lt;P&gt;Load IncidentID,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count(IncidentID) as Visits,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; max(AttendedTime)-min(AttendedTime) as TotalTime;&lt;/P&gt;&lt;P&gt;Resident Data_2 Group By IncidentID;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As mentioned the syntax isn't checked so you may need to make some slight changes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any problems; post an example file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Matt - Visual Analytics Ltd&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Aug 2011 15:09:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/find-next-value-using-script/m-p/272677#M102084</guid>
      <dc:creator>matt_crowther</dc:creator>
      <dc:date>2011-08-15T15:09:59Z</dc:date>
    </item>
  </channel>
</rss>

