<?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: Set analysis to get the previous value isn't working in Search the Community</title>
    <link>https://community.qlik.com/t5/Search-the-Community/Set-analysis-to-get-the-previous-value-isn-t-working/m-p/1779054#M30</link>
    <description>&lt;P&gt;Try:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;sum({$&amp;lt;number_quarter = {$(=&lt;FONT color="#FF0000"&gt;Max&lt;/FONT&gt;(number_quarter)-1)}&amp;gt;} sales)&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 01 Feb 2021 17:32:27 GMT</pubDate>
    <dc:creator>sonkumamon</dc:creator>
    <dc:date>2021-02-01T17:32:27Z</dc:date>
    <item>
      <title>Set analysis to get the previous value isn't working</title>
      <link>https://community.qlik.com/t5/Search-the-Community/Set-analysis-to-get-the-previous-value-isn-t-working/m-p/1779051#M29</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I am using a set analysis expression to calculate the sales for the previous quarter of the selection. Here is a sample of the data:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;number_quarter&lt;/TD&gt;&lt;TD&gt;sales&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The expression being used is this one:&amp;nbsp;sum({$&amp;lt;number_quarter = {$(=Only(number_quarter)-1)}&amp;gt;} sales)&lt;/P&gt;&lt;P&gt;I was expecting that, when quarter Q4 is selected (not the same dimension as the number_quarter dimension, but also representing the quarter) then the sum of the sales for the previous quarter would be 4. But the formula is returning zero.&lt;/P&gt;&lt;P&gt;Anyone knows why this is happening? Also, in the edit expression screen the preview shows that there is any error (the $(=Only(number_quarter)-1) part of the formula shows 3 when quarter Q4 is selected.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 17:34:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Search-the-Community/Set-analysis-to-get-the-previous-value-isn-t-working/m-p/1779051#M29</guid>
      <dc:creator>Leandro_Silva</dc:creator>
      <dc:date>2021-02-01T17:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: Set analysis to get the previous value isn't working</title>
      <link>https://community.qlik.com/t5/Search-the-Community/Set-analysis-to-get-the-previous-value-isn-t-working/m-p/1779054#M30</link>
      <description>&lt;P&gt;Try:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;sum({$&amp;lt;number_quarter = {$(=&lt;FONT color="#FF0000"&gt;Max&lt;/FONT&gt;(number_quarter)-1)}&amp;gt;} sales)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 17:32:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Search-the-Community/Set-analysis-to-get-the-previous-value-isn-t-working/m-p/1779054#M30</guid>
      <dc:creator>sonkumamon</dc:creator>
      <dc:date>2021-02-01T17:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: Set analysis to get the previous value isn't working</title>
      <link>https://community.qlik.com/t5/Search-the-Community/Set-analysis-to-get-the-previous-value-isn-t-working/m-p/1779057#M31</link>
      <description>&lt;P&gt;As you are using Only(number_quarter), then you will only get output of you expression if you only have one [number_quarter] in your selection. With more than one number_quarter in your selection your only() function will return null.&lt;/P&gt;&lt;P&gt;But your expression should work as intended given your scenario. (I created a QV app that I attached)&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Vegar_0-1612201174292.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/48137i4CC4F9CE85A5C689/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Vegar_0-1612201174292.png" alt="Vegar_0-1612201174292.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 17:39:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Search-the-Community/Set-analysis-to-get-the-previous-value-isn-t-working/m-p/1779057#M31</guid>
      <dc:creator>Vegar</dc:creator>
      <dc:date>2021-02-01T17:39:34Z</dc:date>
    </item>
    <item>
      <title>Re: Set analysis to get the previous value isn't working</title>
      <link>https://community.qlik.com/t5/Search-the-Community/Set-analysis-to-get-the-previous-value-isn-t-working/m-p/1779087#M32</link>
      <description>&lt;P&gt;Hi Vegar. Thanks for the answer.&lt;/P&gt;&lt;P&gt;At first i really thought that&amp;nbsp;I wouldn’t need to select a number_quarter since a quarter was already selected.&lt;/P&gt;&lt;P&gt;But to overcome this I wrote the following expression: sum({$&amp;lt;quarter = P({1&amp;lt;number_quarter = {$(=Only(number_quarter)-1)}&amp;gt;})&amp;gt;} sales). The quarter dimension is the number quarter as a string (Q1, Q2, Q3 and Q4).&lt;/P&gt;&lt;P&gt;The P() function does the magic, since it consider values that are implied by the selection of the quarter.&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 19:18:58 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Search-the-Community/Set-analysis-to-get-the-previous-value-isn-t-working/m-p/1779087#M32</guid>
      <dc:creator>Leandro_Silva</dc:creator>
      <dc:date>2021-02-01T19:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: Set analysis to get the previous value isn't working</title>
      <link>https://community.qlik.com/t5/Search-the-Community/Set-analysis-to-get-the-previous-value-isn-t-working/m-p/1779106#M33</link>
      <description>&lt;P&gt;Thats great that you figured out an soltion that worked for you.&lt;/P&gt;&lt;P&gt;You left the information about your [quarter] field out of your initial data sample.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When creating a set expression you could consider each modifier as a selection in the datamodel. In your early example you where using the current selected set $. You where saying that you had made a selection on [quarter] field and with your&amp;nbsp;set modifier/selection on number_quarter your where generating an non exsistent selection.&amp;nbsp; You where trying to calculate the sum of sales where quarter='Q4' and quarter_number=3. That combination will return zero, to get what you desire you will need to cancel the quarter selection from your $-set. You can do this like below.&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;sum({$&amp;lt;&lt;STRONG&gt;quarter=&lt;/STRONG&gt;, number_quarter = {$(=Only(number_quarter)-1)}&amp;gt;} sales)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Your solution using p() will also work, but I consider my solution above less complex.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 20:35:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Search-the-Community/Set-analysis-to-get-the-previous-value-isn-t-working/m-p/1779106#M33</guid>
      <dc:creator>Vegar</dc:creator>
      <dc:date>2021-02-01T20:35:46Z</dc:date>
    </item>
  </channel>
</rss>

