<?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: [SOLVED] Left Outer Join to same Resident Table in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Left-Outer-Join-to-same-Resident-Table/m-p/1820836#M1213474</link>
    <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/145268"&gt;@QIT&lt;/a&gt;&amp;nbsp; mark the appropriate answer as correct&lt;/P&gt;</description>
    <pubDate>Thu, 08 Jul 2021 22:16:30 GMT</pubDate>
    <dc:creator>Kushal_Chawda</dc:creator>
    <dc:date>2021-07-08T22:16:30Z</dc:date>
    <item>
      <title>Left Outer Join to same Resident Table</title>
      <link>https://community.qlik.com/t5/QlikView/Left-Outer-Join-to-same-Resident-Table/m-p/1820692#M1213459</link>
      <description>&lt;P&gt;Hello all.&lt;/P&gt;&lt;P&gt;I have a simple resident table (loaded from excel file) like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;yyyymm|code|balance
202101| A  |    100
202102| A  |    110
202103| A  |    120
202104| A  |    100
202105| A  |    140
202106| A  |    110
202107| A  |    150
202101| B  |    200
202102| B  |    230
202103| B  |    220
202104| B  |    250
202105| B  |    210
202106| B  |    230
202107| B  |    250
202101| C  |    290
202102| C  |    330
202103| C  |    350
202104| C  |    350
202105| C  |    300
202106| C  |    380
202107| C  |    320&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b ChMk0b"&gt;&lt;SPAN&gt;I would like to LEFT JOIN this table with itself in order to get, for each month (YYYYMM), the balance of the previous month for the same code.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b ChMk0b"&gt;&lt;SPAN&gt;I can do this in SQL (MS SQL Server) with both of these queries: &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SELECT *,balance-prev_balance AS diff FROM (
SELECT yyyymm, code, balance,
LAG(balance,1) OVER (PARTITION BY code ORDER BY yyyymm) prev_balance
FROM UserhrNPF.test
) x;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SELECT *,balance-prev_balance AS diff FROM (
SELECT c.*,
(SELECT TOP 1 p.balance
FROM UserhrNPF.test p
WHERE p.code = c.code AND p.yyyymm &amp;lt; c.yyyymm
ORDER BY p.yyyymm DESC) prev_balance
FROM UserhrNPF.test c
) x;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b ChMk0b"&gt;&lt;SPAN&gt;... but I am not able to do this with Qlik View.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b ChMk0b"&gt;&lt;SPAN&gt;The desired result should be like this: &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;yyyymm|code|balance|prev_balance|diff
202101| A  |    100|            |  
202102| A  |    110|         100|  10
202103| A  |    120|         110|  10
202104| A  |    100|         120| -20
202105| A  |    140|         100|  40
202106| A  |    110|         140| -30
202107| A  |    150|         110|  40
202101| B  |    200|            |  
202102| B  |    230|         200|  30
202103| B  |    220|         230| -10
202104| B  |    250|         220|  30
202105| B  |    210|         250| -40
202106| B  |    230|         210|  20
202107| B  |    250|         230|  20
202101| C  |    290|            |  
202102| C  |    330|         290|  40
202103| C  |    350|         330|  20
202104| C  |    350|         350|  0
202105| C  |    300|         350| -50
202106| C  |    380|         300|  80
202107| C  |    320|         380| -60&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b ChMk0b"&gt;&lt;SPAN&gt;Thanks for any help.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 13:52:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Left-Outer-Join-to-same-Resident-Table/m-p/1820692#M1213459</guid>
      <dc:creator>QIT</dc:creator>
      <dc:date>2021-07-09T13:52:24Z</dc:date>
    </item>
    <item>
      <title>Re: Left Outer Joint to same Resident Table</title>
      <link>https://community.qlik.com/t5/QlikView/Left-Outer-Join-to-same-Resident-Table/m-p/1820708#M1213463</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="avinashelite_0-1625742143448.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/58260i65C97F97E68CD19D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="avinashelite_0-1625742143448.png" alt="avinashelite_0-1625742143448.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Find the solution below&lt;/P&gt;&lt;P&gt;LOAD *,&lt;BR /&gt;balance-prev_balance as diff;&lt;BR /&gt;LOAD *,&lt;BR /&gt;Previous(balance) as prev_balance;&lt;BR /&gt;LOAD * Inline&lt;BR /&gt;[&lt;BR /&gt;yyyymm,code,balance&lt;BR /&gt;202101, A , 100&lt;BR /&gt;202102, A , 110&lt;BR /&gt;202103, A , 120&lt;BR /&gt;202104, A , 100&lt;BR /&gt;202105, A , 140&lt;BR /&gt;202106, A , 110&lt;BR /&gt;202107, A , 150&lt;BR /&gt;202101, B , 200&lt;BR /&gt;202102, B , 230&lt;BR /&gt;202103, B , 220&lt;BR /&gt;202104, B , 250&lt;BR /&gt;202105, B , 210&lt;BR /&gt;202106, B , 230&lt;BR /&gt;202107, B , 250&lt;BR /&gt;202101, C , 290&lt;BR /&gt;202102, C , 330&lt;BR /&gt;202103, C , 350&lt;BR /&gt;202104, C , 350&lt;BR /&gt;202105, C , 300&lt;BR /&gt;202106, C , 380&lt;BR /&gt;202107, C , 320&lt;BR /&gt;]&lt;BR /&gt;;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 11:03:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Left-Outer-Join-to-same-Resident-Table/m-p/1820708#M1213463</guid>
      <dc:creator>avinashelite</dc:creator>
      <dc:date>2021-07-08T11:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: Left Outer Joint to same Resident Table</title>
      <link>https://community.qlik.com/t5/QlikView/Left-Outer-Join-to-same-Resident-Table/m-p/1820742#M1213469</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/145268"&gt;@QIT&lt;/a&gt;&amp;nbsp; try below&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Data:
LOAD yyyymm,
     code,
     balance
FROM table;

Final:
LOAD *,
     previous(balance) as prev_bal,
     balance - previous(balance) as diff
resident Data
order by code,yyyymm;

drop table Data;&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 08 Jul 2021 13:24:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Left-Outer-Join-to-same-Resident-Table/m-p/1820742#M1213469</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2021-07-08T13:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: [SOLVED] Left Outer Join to same Resident Table</title>
      <link>https://community.qlik.com/t5/QlikView/Left-Outer-Join-to-same-Resident-Table/m-p/1820836#M1213474</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/145268"&gt;@QIT&lt;/a&gt;&amp;nbsp; mark the appropriate answer as correct&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 22:16:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Left-Outer-Join-to-same-Resident-Table/m-p/1820836#M1213474</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2021-07-08T22:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: Left Outer Join to same Resident Table</title>
      <link>https://community.qlik.com/t5/QlikView/Left-Outer-Join-to-same-Resident-Table/m-p/1821065#M1213517</link>
      <description>&lt;P&gt;Sorry but the problem seems a bit more complex.&lt;BR /&gt;My queries take the previous values only if the "code" is the same while in the proposed solutions the previous ones is taken even if the code is different (instead of null).&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 14:19:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Left-Outer-Join-to-same-Resident-Table/m-p/1821065#M1213517</guid>
      <dc:creator>QIT</dc:creator>
      <dc:date>2021-07-09T14:19:25Z</dc:date>
    </item>
    <item>
      <title>Re: Left Outer Join to same Resident Table</title>
      <link>https://community.qlik.com/t5/QlikView/Left-Outer-Join-to-same-Resident-Table/m-p/1821067#M1213518</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/145268"&gt;@QIT&lt;/a&gt;&amp;nbsp; try below&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Data:
LOAD yyyymm,
     code,
     balance
FROM table;

Final:
LOAD *,
     if(code=previous(code), previous(balance)) as prev_bal,
     if(code=previous(code),balance-previous(balance)) as diff
resident Data
order by code,yyyymm;

drop table Data;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 14:24:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Left-Outer-Join-to-same-Resident-Table/m-p/1821067#M1213518</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2021-07-09T14:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: Left Outer Join to same Resident Table</title>
      <link>https://community.qlik.com/t5/QlikView/Left-Outer-Join-to-same-Resident-Table/m-p/1821109#M1213523</link>
      <description>&lt;P&gt;Great! Thank you very much!&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 16:24:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Left-Outer-Join-to-same-Resident-Table/m-p/1821109#M1213523</guid>
      <dc:creator>QIT</dc:creator>
      <dc:date>2021-07-09T16:24:34Z</dc:date>
    </item>
  </channel>
</rss>

