<?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: Fetch values for current year and last year using peek in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Fetch-values-for-Max-date-and-Min-date-using-peek-by-ID/m-p/2036509#M1222556</link>
    <description>&lt;P&gt;Hi &lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/17935"&gt;@MayilVahanan&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Thanks for your quick replies !!!&lt;/P&gt;
&lt;P&gt;I just tried your script but unfortunately it's not working which I am looking for&lt;/P&gt;
&lt;P&gt;Sorry maybe&amp;nbsp; I have not provided the correct requirement.I am trying to explain more in detail here(included future date into dataset to support my requirement)&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Dataset:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Id Date Amount&lt;/P&gt;
&lt;P&gt;1 01-01-2022 100&lt;/P&gt;
&lt;P&gt;1 01-01-2023 200&lt;/P&gt;
&lt;P&gt;2 01-01-2022 400&lt;/P&gt;
&lt;P&gt;2 01-01-2023 300&lt;/P&gt;
&lt;P&gt;3 01-01-2023 600&lt;/P&gt;
&lt;P&gt;3 01-01-2024 500&lt;/P&gt;
&lt;P&gt;I will have previous years, current year or maybe future year in my dataset.so need to take the value by checking max date for a id and min date for a id .I am correctly getting value for Current year amount with my code(please see below) but not able to get the values for Previous year amount(for a id).&lt;/P&gt;
&lt;P&gt;And also I need current year and previous year on minimum date's row for all id.&lt;/P&gt;
&lt;P&gt;I am sharing screenshot for Current output which I followed your script along with expected result.&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="20230210_175727.jpg" style="width: 3041px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/100196i705D0262401429B6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="20230210_175727.jpg" alt="20230210_175727.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Earlier,I&amp;nbsp; achieved what i am looking for the Current Year Amount with below script(not getting for previous)&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;New:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Load *,&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;If(ID=peek('ID'),peek('Amount')) as Current_Year_Amount,&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;If(ID=peek('ID'),RangeMin(peek('Amount'),Amount)) as Previous_Year_Amount&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Resident Test order by ID,Date desc;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 10 Feb 2023 19:41:11 GMT</pubDate>
    <dc:creator>Rsaiq</dc:creator>
    <dc:date>2023-02-10T19:41:11Z</dc:date>
    <item>
      <title>Fetch values for Max date and Min date using peek by ID</title>
      <link>https://community.qlik.com/t5/QlikView/Fetch-values-for-Max-date-and-Min-date-using-peek-by-ID/m-p/2036365#M1222548</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to fetch the current year value and last year value by Id and date and storing it in another field using peek .&lt;/P&gt;
&lt;P&gt;I am successfully getting the result for Current Year as I am fetching the value which are present for max year but same thing is not working with previous year.Below are my dataset, script&amp;nbsp; and current output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Dataset:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Id Date Amount&lt;/P&gt;
&lt;P&gt;1 01-01-2022 100&lt;/P&gt;
&lt;P&gt;1 01-01-2023 200&lt;/P&gt;
&lt;P&gt;2 01-01-2022 400&lt;/P&gt;
&lt;P&gt;2 01-01-2023 300&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Script:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Test:&lt;/P&gt;
&lt;P&gt;Load ID,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Date,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Amount&lt;/P&gt;
&lt;P&gt;From xyz;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;New:&lt;/P&gt;
&lt;P&gt;Load *,&lt;/P&gt;
&lt;P&gt;If(ID=peek('ID'),peek('Amount')) as Current_Year_Amount,&lt;/P&gt;
&lt;P&gt;If(ID=peek('ID'),RangeMin(peek('Amount'),Amount)) as Previous_Year_Amount&lt;/P&gt;
&lt;P&gt;Resident Test order by ID,Date desc;&lt;/P&gt;
&lt;P&gt;Drop table Test;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Output:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="20230210_140428.jpg" style="width: 3384px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/100164i20DF80B9B23649F0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="20230210_140428.jpg" alt="20230210_140428.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Could anyone please help me to get this done .&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 14:02:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Fetch-values-for-Max-date-and-Min-date-using-peek-by-ID/m-p/2036365#M1222548</guid>
      <dc:creator>Rsaiq</dc:creator>
      <dc:date>2023-02-10T14:02:35Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch values for current year and last year using peek</title>
      <link>https://community.qlik.com/t5/QlikView/Fetch-values-for-Max-date-and-Min-date-using-peek-by-ID/m-p/2036374#M1222549</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;You can use set analysis to achieve this one in front end.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, if you want to achieve in back end, try like below&lt;/P&gt;
&lt;P&gt;Data:&lt;BR /&gt;LOAD *, If(Year(Today()) = Year(Date), Amount) as CurrentYearAmount, if(Year(Today())-1 = Year(Date), Amount) as PrevYearAmount INLINE [&lt;BR /&gt;Id Date Amount&lt;BR /&gt;&lt;BR /&gt;1 01-01-2022 100&lt;BR /&gt;&lt;BR /&gt;1 01-01-2023 200&lt;BR /&gt;&lt;BR /&gt;2 01-01-2022 400&lt;BR /&gt;&lt;BR /&gt;2 01-01-2023 300&lt;BR /&gt;](delimiter is ' ');&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 08:49:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Fetch-values-for-Max-date-and-Min-date-using-peek-by-ID/m-p/2036374#M1222549</guid>
      <dc:creator>MayilVahanan</dc:creator>
      <dc:date>2023-02-10T08:49:25Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch values for current year and last year using peek</title>
      <link>https://community.qlik.com/t5/QlikView/Fetch-values-for-Max-date-and-Min-date-using-peek-by-ID/m-p/2036379#M1222550</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/17935"&gt;@MayilVahanan&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Thanks for your reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please help me for set analysis expression for front end.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 08:55:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Fetch-values-for-Max-date-and-Min-date-using-peek-by-ID/m-p/2036379#M1222550</guid>
      <dc:creator>Rsaiq</dc:creator>
      <dc:date>2023-02-10T08:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch values for current year and last year using peek</title>
      <link>https://community.qlik.com/t5/QlikView/Fetch-values-for-Max-date-and-Min-date-using-peek-by-ID/m-p/2036380#M1222551</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;You can bring Year field in the front end.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data:&lt;BR /&gt;LOAD *,Year(Date) as Year INLINE [&lt;BR /&gt;Id Date Amount&lt;BR /&gt;&lt;BR /&gt;1 01-01-2022 100&lt;BR /&gt;&lt;BR /&gt;1 01-01-2023 200&lt;BR /&gt;&lt;BR /&gt;2 01-01-2022 400&lt;BR /&gt;&lt;BR /&gt;2 01-01-2023 300&lt;BR /&gt;](delimiter is ' ');&lt;/P&gt;
&lt;P&gt;Current Year: Sum({&amp;lt;Year={$(=Max(Year))}&amp;gt;}Amount)&lt;/P&gt;
&lt;P&gt;Previous Year: Sum({&amp;lt;Year={$(=Max(Year)-1)}&amp;gt;}Amount)&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 08:58:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Fetch-values-for-Max-date-and-Min-date-using-peek-by-ID/m-p/2036380#M1222551</guid>
      <dc:creator>MayilVahanan</dc:creator>
      <dc:date>2023-02-10T08:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch values for current year and last year using peek</title>
      <link>https://community.qlik.com/t5/QlikView/Fetch-values-for-Max-date-and-Min-date-using-peek-by-ID/m-p/2036384#M1222552</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Backed script is working fine which you provide on max year but problem is like it will work only when we have id with current year but it will not give result if don't have the max year for ID let me modify the dataset&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Dataset:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Id Date Amount&lt;/P&gt;
&lt;P&gt;1 &lt;STRONG&gt;01-01-2020&lt;/STRONG&gt; 100&lt;/P&gt;
&lt;P&gt;1 &lt;STRONG&gt;01-01-2021&lt;/STRONG&gt; 200&lt;/P&gt;
&lt;P&gt;2 &lt;STRONG&gt;01-01-2020&lt;/STRONG&gt; 400&lt;/P&gt;
&lt;P&gt;2 &lt;STRONG&gt;01-01-2021&lt;/STRONG&gt; 300&lt;/P&gt;
&lt;P&gt;Now we don't have the current year in this data set.It will not give result for Previous Year.&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 09:03:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Fetch-values-for-Max-date-and-Min-date-using-peek-by-ID/m-p/2036384#M1222552</guid>
      <dc:creator>Rsaiq</dc:creator>
      <dc:date>2023-02-10T09:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch values for current year and last year using peek</title>
      <link>https://community.qlik.com/t5/QlikView/Fetch-values-for-Max-date-and-Min-date-using-peek-by-ID/m-p/2036388#M1222553</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;Front end will satisfy all your requirements.&lt;/P&gt;
&lt;P&gt;For Back end, in that case, you need to find the Year of max(date) and then use in the if condition.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Its depends on ur requirement and data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data:&lt;BR /&gt;LOAD *,Year(Date) as Year INLINE [&lt;BR /&gt;Id Date Amount&lt;BR /&gt;&lt;BR /&gt;1 01-01-2020 100&lt;BR /&gt;&lt;BR /&gt;1 01-01-2021 200&lt;BR /&gt;&lt;BR /&gt;2 01-01-2020 400&lt;BR /&gt;&lt;BR /&gt;2 01-01-2021 300&lt;BR /&gt;](delimiter is ' ');&lt;/P&gt;
&lt;P&gt;MaxData:&lt;BR /&gt;Load Max(Date) as MaxDate Resident Data;&lt;/P&gt;
&lt;P&gt;Let vMaxYear = Year(Peek('MaxDate'));&lt;/P&gt;
&lt;P&gt;Load *, If(Year(Date) = $(vMaxYear), Amount) as CurrentYear, if(Year(Date) = $(vMaxYear)-1, Amount) as PrevYear Resident Data;&lt;/P&gt;
&lt;P&gt;DROP Table Data, MaxData;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 09:12:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Fetch-values-for-Max-date-and-Min-date-using-peek-by-ID/m-p/2036388#M1222553</guid>
      <dc:creator>MayilVahanan</dc:creator>
      <dc:date>2023-02-10T09:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch values for current year and last year using peek</title>
      <link>https://community.qlik.com/t5/QlikView/Fetch-values-for-Max-date-and-Min-date-using-peek-by-ID/m-p/2036509#M1222556</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/17935"&gt;@MayilVahanan&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Thanks for your quick replies !!!&lt;/P&gt;
&lt;P&gt;I just tried your script but unfortunately it's not working which I am looking for&lt;/P&gt;
&lt;P&gt;Sorry maybe&amp;nbsp; I have not provided the correct requirement.I am trying to explain more in detail here(included future date into dataset to support my requirement)&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Dataset:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Id Date Amount&lt;/P&gt;
&lt;P&gt;1 01-01-2022 100&lt;/P&gt;
&lt;P&gt;1 01-01-2023 200&lt;/P&gt;
&lt;P&gt;2 01-01-2022 400&lt;/P&gt;
&lt;P&gt;2 01-01-2023 300&lt;/P&gt;
&lt;P&gt;3 01-01-2023 600&lt;/P&gt;
&lt;P&gt;3 01-01-2024 500&lt;/P&gt;
&lt;P&gt;I will have previous years, current year or maybe future year in my dataset.so need to take the value by checking max date for a id and min date for a id .I am correctly getting value for Current year amount with my code(please see below) but not able to get the values for Previous year amount(for a id).&lt;/P&gt;
&lt;P&gt;And also I need current year and previous year on minimum date's row for all id.&lt;/P&gt;
&lt;P&gt;I am sharing screenshot for Current output which I followed your script along with expected result.&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="20230210_175727.jpg" style="width: 3041px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/100196i705D0262401429B6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="20230210_175727.jpg" alt="20230210_175727.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Earlier,I&amp;nbsp; achieved what i am looking for the Current Year Amount with below script(not getting for previous)&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;New:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Load *,&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;If(ID=peek('ID'),peek('Amount')) as Current_Year_Amount,&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;If(ID=peek('ID'),RangeMin(peek('Amount'),Amount)) as Previous_Year_Amount&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Resident Test order by ID,Date desc;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 19:41:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Fetch-values-for-Max-date-and-Min-date-using-peek-by-ID/m-p/2036509#M1222556</guid>
      <dc:creator>Rsaiq</dc:creator>
      <dc:date>2023-02-10T19:41:11Z</dc:date>
    </item>
    <item>
      <title>Re: Fetch values for current year and last year using peek</title>
      <link>https://community.qlik.com/t5/QlikView/Fetch-values-for-Max-date-and-Min-date-using-peek-by-ID/m-p/2036809#M1222571</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/17935"&gt;@MayilVahanan&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have achieved what I was looking for the&amp;nbsp;Previous_Year_Amount.I did modify the script using rangemax.Thanks for your replies.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;RangeMax(if(ID=previous(ID),Amount)) as Previous_Year_Amount&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Feb 2023 08:54:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Fetch-values-for-Max-date-and-Min-date-using-peek-by-ID/m-p/2036809#M1222571</guid>
      <dc:creator>Rsaiq</dc:creator>
      <dc:date>2023-02-11T08:54:21Z</dc:date>
    </item>
  </channel>
</rss>

