<?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: Looking at previous rows until a specific value is found in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Looking-at-previous-rows-until-a-specific-value-is-found/m-p/1253675#M859186</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not really sure what you're trying to achieve here, I think you need to expand on your sample data and make the explanation a little clearer....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1- what value to you want to return&lt;/P&gt;&lt;P&gt;2- where should this value return to? a variable?&lt;/P&gt;&lt;P&gt;3- what defines the order of the data?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But as a loose idea yes you can write loops into a script&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 16 Jan 2017 13:17:00 GMT</pubDate>
    <dc:creator>adamdavi3s</dc:creator>
    <dc:date>2017-01-16T13:17:00Z</dc:date>
    <item>
      <title>Looking at previous rows until a specific value is found</title>
      <link>https://community.qlik.com/t5/QlikView/Looking-at-previous-rows-until-a-specific-value-is-found/m-p/1253674#M859185</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am looking at using the peek function to return a value based on a specific condition&lt;/P&gt;&lt;P&gt;I have managed to get the peek function to return the correct value when I know how the number of rows, however the number of rows changes&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to use peek function to look at any number of rows above until a condition is met, then return the value in this row&lt;/P&gt;&lt;P&gt;I am essentially looking where the points scored originated from (Red Zone or Blue Zone)&lt;/P&gt;&lt;P&gt;The ''Pass'' rows differs every time (can be anything from 1 to 50)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sample dataset below&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Category&lt;/P&gt;&lt;P&gt;Red Zone&lt;/P&gt;&lt;P&gt;Pass&lt;/P&gt;&lt;P&gt;Pass&lt;/P&gt;&lt;P&gt;Pass&lt;/P&gt;&lt;P&gt;Point Scored&lt;/P&gt;&lt;P&gt;Blue Zone&lt;/P&gt;&lt;P&gt;Pass&lt;/P&gt;&lt;P&gt;Pass&lt;/P&gt;&lt;P&gt;Pass&lt;/P&gt;&lt;P&gt;Pass&lt;/P&gt;&lt;P&gt;Pass&lt;/P&gt;&lt;P&gt;Pass&lt;/P&gt;&lt;P&gt;Point Scored&lt;/P&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/Looking-at-previous-rows-until-a-specific-value-is-found/m-p/1253674#M859185</guid>
      <dc:creator />
      <dc:date>2020-11-25T16:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: Looking at previous rows until a specific value is found</title>
      <link>https://community.qlik.com/t5/QlikView/Looking-at-previous-rows-until-a-specific-value-is-found/m-p/1253675#M859186</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not really sure what you're trying to achieve here, I think you need to expand on your sample data and make the explanation a little clearer....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1- what value to you want to return&lt;/P&gt;&lt;P&gt;2- where should this value return to? a variable?&lt;/P&gt;&lt;P&gt;3- what defines the order of the data?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But as a loose idea yes you can write loops into a script&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jan 2017 13:17:00 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Looking-at-previous-rows-until-a-specific-value-is-found/m-p/1253675#M859186</guid>
      <dc:creator>adamdavi3s</dc:creator>
      <dc:date>2017-01-16T13:17:00Z</dc:date>
    </item>
    <item>
      <title>Re: Looking at previous rows until a specific value is found</title>
      <link>https://community.qlik.com/t5/QlikView/Looking-at-previous-rows-until-a-specific-value-is-found/m-p/1253676#M859187</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's not possible to include such a condition directly into the peek-function but you could imbed the peek-function within multiple nested if-loops - whereby this would only work if you knows the max. number of iterations and they are not more than 99 (it's a qlikview limitation by nested if-loops) and it would be neither very elegant nor very performant - but by smaller datasets it could be a pragmatism solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another way might be to aggregate the fieldvalues from Category per concat and join them back to your originate table and to count the number of values within the aggregation and using then further string-functions like index(), subfield() and so on to pick the right value - it's probably not very easy and it will need some efforts. In general I mean somehing like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;table:&lt;/P&gt;&lt;P&gt;load&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AnyID, Category, if(AnyID = previous(AnyID), peek('IterNo') + 1, 1) as IterNo&lt;/P&gt;&lt;P&gt;resident Source order by AnyID;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;left join (table)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;load&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AnyID,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; concat(Category, ',', Iterno) as CategoryConcat,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; concat(IterNo, ',', Iterno) as IternoConcat,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; substringcount(concat(Category, ',', Iterno), ',') + 1 as CountConcat&lt;/P&gt;&lt;P&gt;resident table;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Further approach might be to create a separate table with this aggregation and running over them a for-loop to grab each record and within this loop are another for-loop or a while-loop probabaly with some furter if-checks to create some new table or just to join the right value to your originate table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this will give you some ideas what might be possible to get nearer to your goal.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Marcus&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jan 2017 16:05:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Looking-at-previous-rows-until-a-specific-value-is-found/m-p/1253676#M859187</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2017-01-16T16:05:47Z</dc:date>
    </item>
    <item>
      <title>Re: Looking at previous rows until a specific value is found</title>
      <link>https://community.qlik.com/t5/QlikView/Looking-at-previous-rows-until-a-specific-value-is-found/m-p/1253677#M859188</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;maybe one solution might be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="QlikCommunity_Thread_246301_Pic1.JPG" class="jive-image image-3" src="https://community.qlik.com/legacyfs/online/149656_QlikCommunity_Thread_246301_Pic1.JPG" style="height: auto; width: auto;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="149655" alt="QlikCommunity_Thread_246301_Pic2.JPG" class="jive-image image-2" src="https://community.qlik.com/legacyfs/online/149655_QlikCommunity_Thread_246301_Pic2.JPG" style="height: auto; width: auto;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14845981091148412" jivemacro_uid="_14845981091148412"&gt;
&lt;P&gt;table1:&lt;/P&gt;
&lt;P&gt;LOAD RecNo() as ID,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Category,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If(Category like '*Zone', Category, Peek('Zone')) as Zone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ceil(Rand()*100) as SomeValue&lt;/P&gt;
&lt;P&gt;INLINE [&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Category&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Red Zone&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Pass&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Pass&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Pass&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Point Scored&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Blue Zone&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Pass&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Pass&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Pass&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Pass&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Pass&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Pass&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Point Scored&lt;/P&gt;
&lt;P&gt;];&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope this helps&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Marco&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jan 2017 20:22:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Looking-at-previous-rows-until-a-specific-value-is-found/m-p/1253677#M859188</guid>
      <dc:creator>MarcoWedel</dc:creator>
      <dc:date>2017-01-16T20:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: Looking at previous rows until a specific value is found</title>
      <link>https://community.qlik.com/t5/QlikView/Looking-at-previous-rows-until-a-specific-value-is-found/m-p/1253678#M859189</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;EM&gt;table1:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;LOAD RecNo() as ID,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Category,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ceil(Rand()*100) as SomeValue&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;INLINE [&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Category&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Red Zone&lt;/EM&gt;&lt;/P&gt;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lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp; ID, Category, &lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&amp;nbsp; if(Category like 'Point*', Peek(Category)) as Zone&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Resident table1&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Where not wildmatch(Category, '*Pass*')&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Order By ID;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="1.png" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/149653_1.png" style="height: auto; width: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 16 Jan 2017 20:57:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Looking-at-previous-rows-until-a-specific-value-is-found/m-p/1253678#M859189</guid>
      <dc:creator>maxgro</dc:creator>
      <dc:date>2017-01-16T20:57:09Z</dc:date>
    </item>
  </channel>
</rss>

