<?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: Peek() in script? in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Peek-in-script/m-p/307651#M588228</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please see QlikView manual (F1 in desktop client) and lookup Peek for guidance and you will find that the function definition.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;SPAN class="Bold"&gt;peek&lt;/SPAN&gt; fieldname [ , row [ , tablename ] ] &lt;SPAN class="Bold"&gt;)&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;SPAN class="Bold"&gt; &lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Bold"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Bold"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Bold"&gt;So in your example above you are using unsuitable parameters. The first param must be a fieldname, hence you can not use the table name as you have done. Also notice that when using peek in a load, you can not use table since the table does not yet exist hence QlikView assumes the current table in such case. The IF statement needs to have an ELSE cause in order to add values when it is not already 0.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Bold"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Bold"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if(DifferenceReading= 0, MeasuringReading-Peek('MeasuringReading'), DifferenceReading) as DifferenceReading&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also you might want to consider that first row will not be able to Peek() since there is no previous row.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if(DifferenceReading=0 AND RecNo() &amp;gt; 1, MeasuringReading-Peek('MeasuringReading'), DifferenceReading) as DifferenceReading&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 18 May 2011 12:30:39 GMT</pubDate>
    <dc:creator>ToniKautto</dc:creator>
    <dc:date>2011-05-18T12:30:39Z</dc:date>
    <item>
      <title>Peek() in script?</title>
      <link>https://community.qlik.com/t5/QlikView/Peek-in-script/m-p/307649#M588226</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;/P&gt;&lt;P&gt;I have a table like the following&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="4447" alt="Measreadings.jpg" class="jive-image-thumbnail jive-image" src="https://community.qlik.com/legacyfs/online/4447_Measreadings.jpg" width="450" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The counterRdgDifference (Counter reading Differences) are coming directly from the database and sometimes those are not calculated as in the case above.&lt;/P&gt;&lt;P&gt;In such case, I need to calculate the counterRdgDifference in Qlikview.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My assumption is using peek in script. I dont know how to do this in expression.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My idea in script:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&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;MeasurementTable:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load *,&lt;/P&gt;&lt;P&gt;if(DifferenceReading= 0, MeasuringReading-Peek('MeasurementTable',-1) as DifferenceReading&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load MeasurementDoc,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Measuringpoint_Key,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MeasuringUnit_Key,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Date_Key,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ReadingDateTime,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MeasRdg_READG_CHGD * Conversion as MeasuringReading,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Difference_CDIFF_CHGD * Conversion as DifferenceReading,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OBJNR_Key,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MeasPosition_PSORT,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Description_PTTXT,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MeterType,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Description_ATBEZ&lt;/P&gt;&lt;P&gt;Resident TableX&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it correct or should I do any aggregation in script based on Measuring point and Measuring Doc??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 May 2011 09:22:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Peek-in-script/m-p/307649#M588226</guid>
      <dc:creator />
      <dc:date>2011-05-18T09:22:13Z</dc:date>
    </item>
    <item>
      <title>Peek() in script?</title>
      <link>https://community.qlik.com/t5/QlikView/Peek-in-script/m-p/307650#M588227</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Hi Sravan,&lt;/P&gt;&lt;P&gt;please provide a short set of sample data I can work with.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rainer&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 May 2011 11:37:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Peek-in-script/m-p/307650#M588227</guid>
      <dc:creator />
      <dc:date>2011-05-18T11:37:09Z</dc:date>
    </item>
    <item>
      <title>Re: Peek() in script?</title>
      <link>https://community.qlik.com/t5/QlikView/Peek-in-script/m-p/307651#M588228</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please see QlikView manual (F1 in desktop client) and lookup Peek for guidance and you will find that the function definition.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;SPAN class="Bold"&gt;peek&lt;/SPAN&gt; fieldname [ , row [ , tablename ] ] &lt;SPAN class="Bold"&gt;)&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;SPAN class="Bold"&gt; &lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Bold"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Bold"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Bold"&gt;So in your example above you are using unsuitable parameters. The first param must be a fieldname, hence you can not use the table name as you have done. Also notice that when using peek in a load, you can not use table since the table does not yet exist hence QlikView assumes the current table in such case. The IF statement needs to have an ELSE cause in order to add values when it is not already 0.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Bold"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="Bold"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if(DifferenceReading= 0, MeasuringReading-Peek('MeasuringReading'), DifferenceReading) as DifferenceReading&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also you might want to consider that first row will not be able to Peek() since there is no previous row.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if(DifferenceReading=0 AND RecNo() &amp;gt; 1, MeasuringReading-Peek('MeasuringReading'), DifferenceReading) as DifferenceReading&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 May 2011 12:30:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Peek-in-script/m-p/307651#M588228</guid>
      <dc:creator>ToniKautto</dc:creator>
      <dc:date>2011-05-18T12:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: Peek() in script?</title>
      <link>https://community.qlik.com/t5/QlikView/Peek-in-script/m-p/307652#M588229</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI Rainer,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for ur answer.&lt;/P&gt;&lt;P&gt;I am still trying but the application is attached now.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Sravan&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;ooops.. I am not getting how to attach a .qvw application:( Any help??&lt;/PRE&gt;&lt;P&gt;Got worked..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Sravan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 May 2011 12:31:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Peek-in-script/m-p/307652#M588229</guid>
      <dc:creator />
      <dc:date>2011-05-18T12:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: Peek() in script?</title>
      <link>https://community.qlik.com/t5/QlikView/Peek-in-script/m-p/307653#M588230</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Toni,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I did exactly what you said and yes I know the syntax of Peek function..As you see I get the negative values and also &lt;STRONG&gt;DifferenceReading cannot be named same..&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 May 2011 12:42:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Peek-in-script/m-p/307653#M588230</guid>
      <dc:creator />
      <dc:date>2011-05-18T12:42:02Z</dc:date>
    </item>
    <item>
      <title>Re: Peek() in script?</title>
      <link>https://community.qlik.com/t5/QlikView/Peek-in-script/m-p/307654#M588231</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sravan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so far I see you have to sort the table by Measuring_PointKey and Date_Key and this will end up in a line like the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if(IsNull(OnHandBalance) and Item_number=peek(Item_number),peek(OnHandBalance),OnHandBalance) as OnHandBalance,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or with your fields:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if(IsNull(DifferenceReading) and Measuring_Key=peek(Measuring_Key),MeasuringReading-Peek('MeasuringReading'),DifferenceReading) as DifferenceReading,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Attached are the application this line comes from.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it helps.&lt;/P&gt;&lt;P&gt;Rainer&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 18pt;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-size: 18pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 May 2011 14:26:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Peek-in-script/m-p/307654#M588231</guid>
      <dc:creator />
      <dc:date>2011-05-18T14:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: Peek() in script?</title>
      <link>https://community.qlik.com/t5/QlikView/Peek-in-script/m-p/307655#M588232</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rainer,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the example. I did exactly the same way, still it does not shows the differences.&lt;/P&gt;&lt;P&gt;I wonder what is happening.&amp;nbsp; Attached is what I did.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;P&gt;Sravan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 May 2011 15:20:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Peek-in-script/m-p/307655#M588232</guid>
      <dc:creator />
      <dc:date>2011-05-18T15:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: Peek() in script?</title>
      <link>https://community.qlik.com/t5/QlikView/Peek-in-script/m-p/307656#M588233</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good morning Sravan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope we are a step closer solving your requirement.&lt;/P&gt;&lt;P&gt;Find the right sort order is the key.&lt;/P&gt;&lt;P&gt;See the attached example. I hope it´s what you are looking for.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rainer&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 May 2011 07:40:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Peek-in-script/m-p/307656#M588233</guid>
      <dc:creator />
      <dc:date>2011-05-19T07:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: Peek() in script?</title>
      <link>https://community.qlik.com/t5/QlikView/Peek-in-script/m-p/307657#M588234</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rainer,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; That really did the trick bringing Datekey before in the Order by statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot&lt;/P&gt;&lt;P&gt;Sravan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 May 2011 08:01:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Peek-in-script/m-p/307657#M588234</guid>
      <dc:creator />
      <dc:date>2011-05-19T08:01:12Z</dc:date>
    </item>
  </channel>
</rss>

