<?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: Previous function with group condition in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Previous-function-with-group-condition/m-p/1860434#M1216108</link>
    <description>&lt;P&gt;Yes, such tasks could be solved with interrecord-functions like previous() or peek(). Important for it is that the load is properly sorted with an appropriate order by statement - which also requires a resident-load or a select-load. In your case it looks that you couldn't get this sorting with your 4 single-fields else you will need to combine them like:&lt;/P&gt;
&lt;P&gt;sub &amp;amp; '|' &amp;amp; branch &amp;amp; '|' &amp;amp; product &amp;amp; '|' &amp;amp; date as OrderField&lt;/P&gt;
&lt;P&gt;and within the final load you will need something like this:&lt;/P&gt;
&lt;P&gt;if(date = previous(date) and branch = previous(branch) ..., previous(sales), 0) ...&lt;/P&gt;
&lt;P&gt;This means the belonging records following direct on each other so that you could with previous() directly access the&amp;nbsp;ancestor record whereby you will need some if-loops to detect when comes a different key which hasn't an ancestor and/or if there are further requirements of conditions or any exception-handling.&lt;/P&gt;
&lt;P&gt;- Marcus&lt;/P&gt;</description>
    <pubDate>Wed, 17 Nov 2021 12:13:34 GMT</pubDate>
    <dc:creator>marcus_sommer</dc:creator>
    <dc:date>2021-11-17T12:13:34Z</dc:date>
    <item>
      <title>Previous function with group condition</title>
      <link>https://community.qlik.com/t5/QlikView/Previous-function-with-group-condition/m-p/1860175#M1216096</link>
      <description>&lt;P&gt;Hi Expert,&lt;/P&gt;
&lt;P&gt;I have a 3 days sales data transactions with detail like this:&lt;/P&gt;
&lt;P&gt;Table:&lt;BR /&gt;LOAD * Inline&lt;BR /&gt;[&lt;BR /&gt;TRX_DATE, PRODUCT, BRANCH, SUB_BRANCH, SALES&lt;BR /&gt;1/1/2021, PRODUCT_A, BRANCH_1, SB001, 173&lt;BR /&gt;1/1/2021, PRODUCT_A, BRANCH_1, SB002, 213&lt;BR /&gt;1/1/2021, PRODUCT_A, BRANCH_1, SB003, 256&lt;BR /&gt;1/1/2021, PRODUCT_A, BRANCH_2, SB004, 85&lt;BR /&gt;1/1/2021, PRODUCT_A, BRANCH_2, SB005, 292&lt;BR /&gt;1/1/2021, PRODUCT_A, BRANCH_3, SB006, 184&lt;BR /&gt;1/1/2021, PRODUCT_A, BRANCH_3, SB007, 130&lt;BR /&gt;1/1/2021, PRODUCT_A, BRANCH_3, SB008, 176&lt;BR /&gt;1/1/2021, PRODUCT_B, BRANCH_1, SB002, 211&lt;BR /&gt;1/1/2021, PRODUCT_B, BRANCH_2, SB004, 121&lt;BR /&gt;1/1/2021, PRODUCT_B, BRANCH_2, SB005, 222&lt;BR /&gt;1/1/2021, PRODUCT_B, BRANCH_3, SB007, 210&lt;BR /&gt;1/2/2021, PRODUCT_A, BRANCH_1, SB001, 89&lt;BR /&gt;1/2/2021, PRODUCT_A, BRANCH_1, SB002, 227&lt;BR /&gt;1/2/2021, PRODUCT_A, BRANCH_1, SB003, 189&lt;BR /&gt;1/2/2021, PRODUCT_A, BRANCH_2, SB004, 291&lt;BR /&gt;1/2/2021, PRODUCT_A, BRANCH_2, SB005, 261&lt;BR /&gt;1/2/2021, PRODUCT_A, BRANCH_3, SB006, 215&lt;BR /&gt;1/2/2021, PRODUCT_A, BRANCH_3, SB007, 250&lt;BR /&gt;1/2/2021, PRODUCT_A, BRANCH_3, SB008, 210&lt;BR /&gt;1/2/2021, PRODUCT_B, BRANCH_1, SB002, 160&lt;BR /&gt;1/2/2021, PRODUCT_B, BRANCH_2, SB004, 253&lt;BR /&gt;1/2/2021, PRODUCT_B, BRANCH_2, SB005, 256&lt;BR /&gt;1/2/2021, PRODUCT_B, BRANCH_3, SB007, 71&lt;BR /&gt;1/3/2021, PRODUCT_A, BRANCH_1, SB001, 126&lt;BR /&gt;1/3/2021, PRODUCT_A, BRANCH_1, SB002, 78&lt;BR /&gt;1/3/2021, PRODUCT_A, BRANCH_1, SB003, 69&lt;BR /&gt;1/3/2021, PRODUCT_A, BRANCH_2, SB004, 54&lt;BR /&gt;1/3/2021, PRODUCT_A, BRANCH_2, SB005, 67&lt;BR /&gt;1/3/2021, PRODUCT_A, BRANCH_3, SB006, 218&lt;BR /&gt;1/3/2021, PRODUCT_A, BRANCH_3, SB007, 89&lt;BR /&gt;1/3/2021, PRODUCT_A, BRANCH_3, SB008, 210&lt;BR /&gt;1/3/2021, PRODUCT_B, BRANCH_1, SB002, 208&lt;BR /&gt;1/3/2021, PRODUCT_B, BRANCH_2, SB004, 273&lt;BR /&gt;1/3/2021, PRODUCT_B, BRANCH_2, SB005, 152&lt;BR /&gt;1/3/2021, PRODUCT_B, BRANCH_3, SB007, 255&lt;BR /&gt;];&lt;/P&gt;
&lt;P&gt;From that data, I want to see previous sales 1 day and previous sales 2 days based on PRODUCT, BRANCH, and SUB_BRANCH. So, the result should be like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dennysetiawan_0-1637115421081.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/66781i25614E294A244629/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dennysetiawan_0-1637115421081.png" alt="dennysetiawan_0-1637115421081.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to do this in load script. It this possible?&lt;/P&gt;
&lt;P&gt;Please help. Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 02:18:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Previous-function-with-group-condition/m-p/1860175#M1216096</guid>
      <dc:creator>dennysetiawan</dc:creator>
      <dc:date>2021-11-17T02:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: Previous function with group condition</title>
      <link>https://community.qlik.com/t5/QlikView/Previous-function-with-group-condition/m-p/1860434#M1216108</link>
      <description>&lt;P&gt;Yes, such tasks could be solved with interrecord-functions like previous() or peek(). Important for it is that the load is properly sorted with an appropriate order by statement - which also requires a resident-load or a select-load. In your case it looks that you couldn't get this sorting with your 4 single-fields else you will need to combine them like:&lt;/P&gt;
&lt;P&gt;sub &amp;amp; '|' &amp;amp; branch &amp;amp; '|' &amp;amp; product &amp;amp; '|' &amp;amp; date as OrderField&lt;/P&gt;
&lt;P&gt;and within the final load you will need something like this:&lt;/P&gt;
&lt;P&gt;if(date = previous(date) and branch = previous(branch) ..., previous(sales), 0) ...&lt;/P&gt;
&lt;P&gt;This means the belonging records following direct on each other so that you could with previous() directly access the&amp;nbsp;ancestor record whereby you will need some if-loops to detect when comes a different key which hasn't an ancestor and/or if there are further requirements of conditions or any exception-handling.&lt;/P&gt;
&lt;P&gt;- Marcus&lt;/P&gt;</description>
      <pubDate>Wed, 17 Nov 2021 12:13:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Previous-function-with-group-condition/m-p/1860434#M1216108</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2021-11-17T12:13:34Z</dc:date>
    </item>
  </channel>
</rss>

