<?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: Top N customers in Current Quarter, Last 4 Quarters and PY in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Top-N-customers-in-Current-Quarter-Last-4-Quarters-and-PY/m-p/1867814#M71668</link>
    <description>&lt;P&gt;there are a couple of components to this:&lt;/P&gt;
&lt;P&gt;1. identify the quarters, one way is determine what quarters you are interested in and store that in a variable which you can use in&amp;nbsp; your set analysis.&amp;nbsp; &lt;BR /&gt;current quarter: vQuarter=&amp;nbsp; &amp;nbsp; =only(quarterRank)&amp;nbsp; - this assumes your user selects a month and this returns the current quarter&lt;/P&gt;
&lt;P&gt;2. save your top N number in a variable which you will also use in your set analysis&lt;BR /&gt;vTopN = 3&amp;nbsp; (you can either use a slider, or a variable selector)&lt;/P&gt;
&lt;P&gt;3. the expression itself.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Sum({&amp;lt;monthDate=, quarterRank={$(vQuarter)}, 
customer={"=rank(Sum({&amp;lt;monthDate=, quarterRank={$(vQuarter)}&amp;gt;}amount))&amp;lt;=$(vTopN)"}
&amp;gt;}amount)
&lt;/LI-CODE&gt;
&lt;P&gt;the first line says: ignore the selected month; select all records with quarterRank =currently selected quarter&lt;BR /&gt;2nd line says select customers where rank &amp;lt;= 3&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;this gives you the top 3 from current quarter.&amp;nbsp; if you want other quarters, you need to build a way for user to select the quarter and then in your vQuarter variable create an expression that returns the desired quarter or quarters.&amp;nbsp; for last x quarters you need to return the quarter ranks concatenated by commas: 8,7,6,5&amp;nbsp; and so on.&amp;nbsp; this just gets inserted into the set analysis&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;you can expand on that&lt;/P&gt;
&lt;P&gt;try this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;data:
load monthDate,
'Q' &amp;amp; CEIL(NUM(MONTH(monthDate))/3) &amp;amp; ' ' &amp;amp; year(monthDate) as quarterYear, 
CEIL(NUM(MONTH(monthDate))/3) + year(monthDate)*10 as quarterCode, 
'C'&amp;amp;iterno() as customer, floor(rand()*100) as amount
while iterno()&amp;lt;11;
load addmonths(monthstart(today()),1-iterno()) as monthDate 
while iterno() &amp;lt;=24;
load 1 autogenerate(1);

tmpQuarters: 
load distinct quarterYear, quarterCode resident data;

noconcatenate quarters:
load quarterYear, rowno() as quarterRank resident tmpQuarters order by quarterCode;

drop table tmpQuarters;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;the table shows which ones are the top for the current quarter , the chart just shows the top 3&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="edwin_0-1638910360232.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/68127iE122FA8ACA05C0AD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="edwin_0-1638910360232.png" alt="edwin_0-1638910360232.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Dec 2021 20:53:33 GMT</pubDate>
    <dc:creator>edwin</dc:creator>
    <dc:date>2021-12-07T20:53:33Z</dc:date>
    <item>
      <title>Top N customers in Current Quarter, Last 4 Quarters and PY</title>
      <link>https://community.qlik.com/t5/App-Development/Top-N-customers-in-Current-Quarter-Last-4-Quarters-and-PY/m-p/1867356#M71623</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;Thanks for your support in advance.&lt;/P&gt;
&lt;P&gt;I created a &lt;STRONG&gt;stacked bar chart, Quarter_Year, Customer as Dimension and Sum of sales as Measure&lt;/STRONG&gt;. As shown below.&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Test Data image.JPG" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/68033iC3F61996C6ECDCCE/image-size/large?v=v2&amp;amp;px=999" role="button" title="Test Data image.JPG" alt="Test Data image.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Now i want to see &lt;FONT color="#FF0000"&gt;Top 3 Customers of Current Quarter&lt;/FONT&gt;, &lt;FONT color="#FF0000"&gt;Top 3 Customer of last 4 Quarters&lt;/FONT&gt; Like this &lt;FONT color="#FF0000"&gt;Top 5 and Top 10&lt;/FONT&gt; customers using d&lt;FONT color="#FF0000"&gt;rop down selection&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;Could you please help me how to do this one.&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Krish&lt;/P&gt;</description>
      <pubDate>Tue, 07 Dec 2021 02:48:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Top-N-customers-in-Current-Quarter-Last-4-Quarters-and-PY/m-p/1867356#M71623</guid>
      <dc:creator>Kris1</dc:creator>
      <dc:date>2021-12-07T02:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: Top N customers in Current Quarter, Last 4 Quarters and PY</title>
      <link>https://community.qlik.com/t5/App-Development/Top-N-customers-in-Current-Quarter-Last-4-Quarters-and-PY/m-p/1867814#M71668</link>
      <description>&lt;P&gt;there are a couple of components to this:&lt;/P&gt;
&lt;P&gt;1. identify the quarters, one way is determine what quarters you are interested in and store that in a variable which you can use in&amp;nbsp; your set analysis.&amp;nbsp; &lt;BR /&gt;current quarter: vQuarter=&amp;nbsp; &amp;nbsp; =only(quarterRank)&amp;nbsp; - this assumes your user selects a month and this returns the current quarter&lt;/P&gt;
&lt;P&gt;2. save your top N number in a variable which you will also use in your set analysis&lt;BR /&gt;vTopN = 3&amp;nbsp; (you can either use a slider, or a variable selector)&lt;/P&gt;
&lt;P&gt;3. the expression itself.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Sum({&amp;lt;monthDate=, quarterRank={$(vQuarter)}, 
customer={"=rank(Sum({&amp;lt;monthDate=, quarterRank={$(vQuarter)}&amp;gt;}amount))&amp;lt;=$(vTopN)"}
&amp;gt;}amount)
&lt;/LI-CODE&gt;
&lt;P&gt;the first line says: ignore the selected month; select all records with quarterRank =currently selected quarter&lt;BR /&gt;2nd line says select customers where rank &amp;lt;= 3&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;this gives you the top 3 from current quarter.&amp;nbsp; if you want other quarters, you need to build a way for user to select the quarter and then in your vQuarter variable create an expression that returns the desired quarter or quarters.&amp;nbsp; for last x quarters you need to return the quarter ranks concatenated by commas: 8,7,6,5&amp;nbsp; and so on.&amp;nbsp; this just gets inserted into the set analysis&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;you can expand on that&lt;/P&gt;
&lt;P&gt;try this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;data:
load monthDate,
'Q' &amp;amp; CEIL(NUM(MONTH(monthDate))/3) &amp;amp; ' ' &amp;amp; year(monthDate) as quarterYear, 
CEIL(NUM(MONTH(monthDate))/3) + year(monthDate)*10 as quarterCode, 
'C'&amp;amp;iterno() as customer, floor(rand()*100) as amount
while iterno()&amp;lt;11;
load addmonths(monthstart(today()),1-iterno()) as monthDate 
while iterno() &amp;lt;=24;
load 1 autogenerate(1);

tmpQuarters: 
load distinct quarterYear, quarterCode resident data;

noconcatenate quarters:
load quarterYear, rowno() as quarterRank resident tmpQuarters order by quarterCode;

drop table tmpQuarters;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;the table shows which ones are the top for the current quarter , the chart just shows the top 3&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="edwin_0-1638910360232.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/68127iE122FA8ACA05C0AD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="edwin_0-1638910360232.png" alt="edwin_0-1638910360232.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Dec 2021 20:53:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Top-N-customers-in-Current-Quarter-Last-4-Quarters-and-PY/m-p/1867814#M71668</guid>
      <dc:creator>edwin</dc:creator>
      <dc:date>2021-12-07T20:53:33Z</dc:date>
    </item>
  </channel>
</rss>

