<?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: Having to find values in previous rows in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Having-to-find-values-in-previous-rows/m-p/1634795#M732778</link>
    <description>&lt;P&gt;Hello Jacques,&lt;BR /&gt;I would do this as follows:&lt;BR /&gt;- Read the Excel sheet into Qlikview (say table tmpTransactions)&lt;BR /&gt;- Read from this temporary table into a new table Transactions, order by reg_no and date (you can only do this from a resident table, not from an excel file)&lt;BR /&gt;- For each line, determine if the previous line contains data about the same reg_no, if so, calculate the difference in kms, and divide this by the no of litres.&lt;BR /&gt;The script I used:&lt;/P&gt;&lt;P&gt;tmpTransactions:&lt;BR /&gt;LOAD Trans_No,&lt;BR /&gt;Date,&lt;BR /&gt;Reg_No,&lt;BR /&gt;Litres_Issued as Litres_Issued,&lt;BR /&gt;Odo as Odo&lt;BR /&gt;FROM&lt;BR /&gt;[Map1.xlsx]&lt;BR /&gt;(ooxml, embedded labels, table is Blad1)&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;Transactions:&lt;BR /&gt;noconcatenate load&lt;BR /&gt;*,&lt;BR /&gt;if (Previous (Reg_No) = Reg_No, Odo - previous (Odo)) as [No_of_kms],&lt;BR /&gt;if (Previous (Reg_No) = Reg_No, (Odo - previous (Odo)) / Litres_Issued ) as [No_of_kms_per_litre]&lt;BR /&gt;resident tmpTransactions&lt;BR /&gt;order by Reg_No, Date asc;&lt;/P&gt;&lt;P&gt;drop table tmpTransactions;&lt;/P&gt;&lt;P&gt;If I do this, I get a table as follows:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="clipboard_image_0.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/21387iCF7EE0DBB214F899/image-size/medium?v=v2&amp;amp;px=400" role="button" title="clipboard_image_0.png" alt="clipboard_image_0.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;As you can see, line number 8 contains 199 litres and 1,46 km / litre.&lt;/P&gt;&lt;P&gt;Hope to have helped you,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Tim Wensink&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 14 Oct 2019 11:18:41 GMT</pubDate>
    <dc:creator>Tim_Wensink</dc:creator>
    <dc:date>2019-10-14T11:18:41Z</dc:date>
    <item>
      <title>Having to find values in previous rows</title>
      <link>https://community.qlik.com/t5/QlikView/Having-to-find-values-in-previous-rows/m-p/1634760#M732777</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;EM&gt;EDIT: Apologies if this post appears twice, but it seems my first post was reported as spam and I can't find it under my profile.&amp;nbsp; I am really in need of assistance with the question below.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;While I am not new to QlikView (still using QlikView 11), I am very much a newbie "developer". I would therefore appreciate any assistance.&amp;nbsp; I have the following extract (simplified version) of an Excel spreadsheet that depicts the fuel usage for three different vehicles.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Trans_No&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Date&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Reg_No&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Litres_Issued&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;Odo&lt;/STRON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gt;CP 44 DZ GP&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;310&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;502,149&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;14&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;05-Aug-2019&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;JH 21 FG GP&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;213&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;489,592&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;15&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;06-Aug-2019&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;JH 21 FG GP&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;200&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;489,831&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;16&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;06-Aug-2019&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;BYZ 652 GP&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;124&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;24,870&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am needing QlikView to calculate the difference in odometer readings (Odo field) by vehicle and subsequently calculate the fuel consumption in km / litre.&lt;/P&gt;&lt;P&gt;By example,&amp;nbsp;&lt;/P&gt;&lt;P&gt;BYZ 652 GP's first fuel fill up was Trans No 5 (transaction id) with an odo reading of 24,193. It refueled as depicted in Trans No 8 with the odo reading on 24,392. Therefore, the kilometres travelled between these two fill-ups would be:&amp;nbsp; 24,392 (current odo reading) - 24,193 (previous odo reading) = 199 kms and should be presented in a column on line 8.&amp;nbsp; The fuel consumption must then be calculated as follows:&lt;/P&gt;&lt;P&gt;Kilometres travelled / litres refueled = 199 kms / 136 litres = 1.46 km / l.&amp;nbsp; This needs to be in the next column on line 8.&lt;/P&gt;&lt;P&gt;I have obviously no idea how to do this.&amp;nbsp; I have read forums all morning on using the Peek and Previous functions, but to no avail. I have even looked at using the Above command, but couldn't get that to work either.&lt;/P&gt;&lt;P&gt;I therefore need a function in determining the difference in kilometres between fill-ups keeping in mind that the previous transaction for that particular vehicle won't necessarily be in the previous row.&amp;nbsp; The function would need to search for the previous fill-up, for that vehicle, that could be any number of transactions before the current one.&lt;/P&gt;&lt;P&gt;I would sincerely appreciate any assistance in this regard.&lt;/P&gt;&lt;P&gt;Thank you kindly,&lt;/P&gt;&lt;P&gt;Jacques&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 19:54:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Having-to-find-values-in-previous-rows/m-p/1634760#M732777</guid>
      <dc:creator>jacqueshol</dc:creator>
      <dc:date>2024-11-16T19:54:24Z</dc:date>
    </item>
    <item>
      <title>Re: Having to find values in previous rows</title>
      <link>https://community.qlik.com/t5/QlikView/Having-to-find-values-in-previous-rows/m-p/1634795#M732778</link>
      <description>&lt;P&gt;Hello Jacques,&lt;BR /&gt;I would do this as follows:&lt;BR /&gt;- Read the Excel sheet into Qlikview (say table tmpTransactions)&lt;BR /&gt;- Read from this temporary table into a new table Transactions, order by reg_no and date (you can only do this from a resident table, not from an excel file)&lt;BR /&gt;- For each line, determine if the previous line contains data about the same reg_no, if so, calculate the difference in kms, and divide this by the no of litres.&lt;BR /&gt;The script I used:&lt;/P&gt;&lt;P&gt;tmpTransactions:&lt;BR /&gt;LOAD Trans_No,&lt;BR /&gt;Date,&lt;BR /&gt;Reg_No,&lt;BR /&gt;Litres_Issued as Litres_Issued,&lt;BR /&gt;Odo as Odo&lt;BR /&gt;FROM&lt;BR /&gt;[Map1.xlsx]&lt;BR /&gt;(ooxml, embedded labels, table is Blad1)&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;Transactions:&lt;BR /&gt;noconcatenate load&lt;BR /&gt;*,&lt;BR /&gt;if (Previous (Reg_No) = Reg_No, Odo - previous (Odo)) as [No_of_kms],&lt;BR /&gt;if (Previous (Reg_No) = Reg_No, (Odo - previous (Odo)) / Litres_Issued ) as [No_of_kms_per_litre]&lt;BR /&gt;resident tmpTransactions&lt;BR /&gt;order by Reg_No, Date asc;&lt;/P&gt;&lt;P&gt;drop table tmpTransactions;&lt;/P&gt;&lt;P&gt;If I do this, I get a table as follows:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="clipboard_image_0.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/21387iCF7EE0DBB214F899/image-size/medium?v=v2&amp;amp;px=400" role="button" title="clipboard_image_0.png" alt="clipboard_image_0.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;As you can see, line number 8 contains 199 litres and 1,46 km / litre.&lt;/P&gt;&lt;P&gt;Hope to have helped you,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Tim Wensink&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Oct 2019 11:18:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Having-to-find-values-in-previous-rows/m-p/1634795#M732778</guid>
      <dc:creator>Tim_Wensink</dc:creator>
      <dc:date>2019-10-14T11:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Having to find values in previous rows</title>
      <link>https://community.qlik.com/t5/QlikView/Having-to-find-values-in-previous-rows/m-p/1634853#M732779</link>
      <description>&lt;P&gt;Hi Tim,&lt;/P&gt;&lt;P&gt;Thank you kindly for your response.&amp;nbsp; I will most definitely be trying that out a little later today.&amp;nbsp; The challenge for me would be to try and understand why that works... &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Jacques&lt;/P&gt;</description>
      <pubDate>Mon, 14 Oct 2019 12:39:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Having-to-find-values-in-previous-rows/m-p/1634853#M732779</guid>
      <dc:creator>jacqueshol</dc:creator>
      <dc:date>2019-10-14T12:39:15Z</dc:date>
    </item>
    <item>
      <title>Re: Having to find values in previous rows</title>
      <link>https://community.qlik.com/t5/QlikView/Having-to-find-values-in-previous-rows/m-p/1634913#M732780</link>
      <description>&lt;P&gt;Hi Tim,&lt;/P&gt;&lt;P&gt;I have tried your solution and it works a charm.&amp;nbsp; Thank you so much.&amp;nbsp; What is really scary, is that I actually understood what you have done.&amp;nbsp; A rather elegant solution.&lt;/P&gt;&lt;P&gt;Thanks again,&lt;/P&gt;&lt;P&gt;Jacques&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Oct 2019 13:16:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Having-to-find-values-in-previous-rows/m-p/1634913#M732780</guid>
      <dc:creator>jacqueshol</dc:creator>
      <dc:date>2019-10-14T13:16:12Z</dc:date>
    </item>
  </channel>
</rss>

