<?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: Using multiple data lines on expression in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Using-multiple-data-lines-on-expression/m-p/935063#M322892</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm assuming that you are doing it in your script, and each line in the example represents a line in your data table...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to load your data and sort it by ID and DateON, using the &lt;STRONG&gt;ORDER BY&lt;/STRONG&gt; clause.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then, you can operate with the functions &lt;STRONG&gt;Peek()&lt;/STRONG&gt; and &lt;STRONG&gt;Previous()&lt;/STRONG&gt; to fetch the data from the previous row. The two functions are similar, but they have their differences and they are not always interchangeable. Depending on your situation, you will need either one or the other. Without too much explanation, I can suggest this rule of thumb - use Previous() to compare the current ID with the previous ID and use Peek() in your calculations:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;IF Previous() THEN Peek().&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you need to "look into the future" and calculated how long until the employee gets goes On again, you'll have to reload your data once again, this time sorting by ID and Date in the descending order, and then you can use Peek() and Previous() again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In case you are curious about more details, check out my new book &lt;STRONG&gt;&lt;EM&gt;QlikView Your Business&lt;/EM&gt;&lt;/STRONG&gt;. In it, I'm demonstrating how to use &lt;STRONG&gt;Previous()&lt;/STRONG&gt; and &lt;STRONG&gt;Peek()&lt;/STRONG&gt; for calculating Inventory Aging balances.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;best,&lt;/P&gt;&lt;P&gt;Oleg Troyansky&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.amazon.com/gp/product/1118949552/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1118949552&amp;amp;linkCode=as2&amp;amp;tag=natursyner0f-20&amp;amp;linkId=HEF4KYLLE22XIQH2"&gt;QlikView Your Business: An expert guide to Business Discovery with QlikView and Qlik Sense&lt;/A&gt;&lt;IMG alt="" border="0" height="1" src="http://ir-na.amazon-adsystem.com/e/ir?t=natursyner0f-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=1118949552" style="border: none !important; margin: 0px !important;" width="1" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 11 Sep 2015 20:14:33 GMT</pubDate>
    <dc:creator>Oleg_Troyansky</dc:creator>
    <dc:date>2015-09-11T20:14:33Z</dc:date>
    <item>
      <title>Using multiple data lines on expression</title>
      <link>https://community.qlik.com/t5/QlikView/Using-multiple-data-lines-on-expression/m-p/935060#M322889</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was wondering if any one can help with an issue imhaving.&lt;/P&gt;&lt;P&gt;First of all, my data: (DATE DD/MM/YYY)&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;ID&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;DateON&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;DateOFF&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;01/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;15/01/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;2&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;02/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;13/01/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;3&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;04/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;24/01/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;17/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;25/01/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;2&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;19/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;24/01/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;26/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;31/01/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;2&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;27/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;30/01/2015&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;3&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;29/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;31/01/2015&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, i have a table that the first expression is the time ON, that the field DateON- DateOFF (not really hard), the problem comes when i need to get the time until hes back on, or the time hes been off.&lt;/P&gt;&lt;P&gt;For example, the table i want would look like:&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;ID&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;DateON&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;DateOFF&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;TimeON&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;TimeOFF&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;01/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;15/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;14&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;2&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;02/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;13/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;11&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;3&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;04/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;24/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;20&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;17/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;25/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;8&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;2&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;19/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;24/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;5&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;26/01/2105&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;31/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;5&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;2&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;27/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;30/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;3&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;3&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;29/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;31/01/2015&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The TimeOFF colum substract the next DateON minus the actual DateOFF.&lt;/P&gt;&lt;P&gt;Is there a way i can do this?&lt;/P&gt;&lt;P&gt;I was thinking i would have to have and extra column on my data that has the next OnDate, but im not sure how to do that. I would have to lookup for matching ids, but im not sure how to do this example. Maybe using some peek inside and if clause, im not sure. It still difficult because you are not sure how many registers youll read before having the same ID again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Sep 2015 20:01:01 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-multiple-data-lines-on-expression/m-p/935060#M322889</guid>
      <dc:creator />
      <dc:date>2015-09-11T20:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using multiple data lines on expression</title>
      <link>https://community.qlik.com/t5/QlikView/Using-multiple-data-lines-on-expression/m-p/935061#M322890</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __default_attr="sql" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14420021002685567" jivemacro_uid="_14420021002685567"&gt;
&lt;P&gt;Temp:&lt;/P&gt;
&lt;P&gt;Load * Inline&lt;/P&gt;
&lt;P&gt;[&lt;/P&gt;
&lt;P&gt;&amp;nbsp; ID, DateON, DateOFF&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 1, 01/01/2015, 15/01/2015&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 2, 02/01/2015, 13/01/2015&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 3, 04/01/2015, 24/01/2015&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 1, 17/01/2015, 25/01/2015&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 2, 19/01/2015, 24/01/2015&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 1, 26/01/2015, 31/01/2015&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 2, 27/01/2015, 30/01/2015&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 3, 29/01/2015, 31/01/2015&lt;/P&gt;
&lt;P&gt;];&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Final:&lt;/P&gt;
&lt;P&gt;Load&lt;/P&gt;
&lt;P&gt;&amp;nbsp; ID,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; DateON,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; DateOFF,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; DateOFF - DateON as TimeON,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; If(ID = Previous(ID),Previous(DateON) - DateOFF, Null()) as TimeOFF&lt;/P&gt;
&lt;P&gt;Resident Temp&lt;/P&gt;
&lt;P&gt;Order By ID, DateON Desc;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Drop Table Temp;&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Sep 2015 20:08:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-multiple-data-lines-on-expression/m-p/935061#M322890</guid>
      <dc:creator>MK_QSL</dc:creator>
      <dc:date>2015-09-11T20:08:27Z</dc:date>
    </item>
    <item>
      <title>Re: Using multiple data lines on expression</title>
      <link>https://community.qlik.com/t5/QlikView/Using-multiple-data-lines-on-expression/m-p/935062#M322891</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;Here you go:&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.PNG" class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/98705_Capture.PNG" style="height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And the table:&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.PNG" class="jive-image image-2" src="https://community.qlik.com/legacyfs/online/98706_Capture.PNG" style="height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Sep 2015 20:13:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-multiple-data-lines-on-expression/m-p/935062#M322891</guid>
      <dc:creator>sinanozdemir</dc:creator>
      <dc:date>2015-09-11T20:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using multiple data lines on expression</title>
      <link>https://community.qlik.com/t5/QlikView/Using-multiple-data-lines-on-expression/m-p/935063#M322892</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm assuming that you are doing it in your script, and each line in the example represents a line in your data table...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to load your data and sort it by ID and DateON, using the &lt;STRONG&gt;ORDER BY&lt;/STRONG&gt; clause.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then, you can operate with the functions &lt;STRONG&gt;Peek()&lt;/STRONG&gt; and &lt;STRONG&gt;Previous()&lt;/STRONG&gt; to fetch the data from the previous row. The two functions are similar, but they have their differences and they are not always interchangeable. Depending on your situation, you will need either one or the other. Without too much explanation, I can suggest this rule of thumb - use Previous() to compare the current ID with the previous ID and use Peek() in your calculations:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;IF Previous() THEN Peek().&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you need to "look into the future" and calculated how long until the employee gets goes On again, you'll have to reload your data once again, this time sorting by ID and Date in the descending order, and then you can use Peek() and Previous() again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In case you are curious about more details, check out my new book &lt;STRONG&gt;&lt;EM&gt;QlikView Your Business&lt;/EM&gt;&lt;/STRONG&gt;. In it, I'm demonstrating how to use &lt;STRONG&gt;Previous()&lt;/STRONG&gt; and &lt;STRONG&gt;Peek()&lt;/STRONG&gt; for calculating Inventory Aging balances.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;best,&lt;/P&gt;&lt;P&gt;Oleg Troyansky&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.amazon.com/gp/product/1118949552/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1118949552&amp;amp;linkCode=as2&amp;amp;tag=natursyner0f-20&amp;amp;linkId=HEF4KYLLE22XIQH2"&gt;QlikView Your Business: An expert guide to Business Discovery with QlikView and Qlik Sense&lt;/A&gt;&lt;IMG alt="" border="0" height="1" src="http://ir-na.amazon-adsystem.com/e/ir?t=natursyner0f-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=1118949552" style="border: none !important; margin: 0px !important;" width="1" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Sep 2015 20:14:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Using-multiple-data-lines-on-expression/m-p/935063#M322892</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2015-09-11T20:14:33Z</dc:date>
    </item>
  </channel>
</rss>

