<?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: Filtering a selection by Rank in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Filtering-a-selection-by-Rank/m-p/2519497#M106270</link>
    <description>&lt;P&gt;Hi Lee,&lt;/P&gt;&lt;P&gt;Short of solving this tricky puzzle, I have some ideas for you to consider:&lt;/P&gt;&lt;P&gt;- Using Set Analysis {1} inside of an AGGR() wouldn't work as expected. You should populate the same set analysis at the AGGR level, like this:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Aggr({1}&amp;nbsp; Rank(TOTAL Sum({1} Amount)), Project)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- Disregarding Project selection within Set Analysis {1} is redundant - {1} ignores any selections&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- TOTAL within rank is only helpful with multiple dimensions, otherwise it's a moot point.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For a while, I couldn't wrap my mind around this problem - how do I compare the global rankings with the rank of the selected project, and how do I cause the table to show all projects, despite the selection. I was about to suggest Alternate States, and then I actually found the solution. Here goes:&lt;BR /&gt;&lt;BR /&gt;1. I defined a variable vSelectedRank, to capture the value of the selected project's rank:&lt;BR /&gt;&lt;BR /&gt;=only({1 &amp;lt;Project=P({$} Project)&amp;gt;} AGGR( {1} rank(sum(Cost), 4, 1), Project) )&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2. Then, in the Dimension, I compare the ranks like this:&lt;BR /&gt;&lt;BR /&gt;={1} AGGR(&lt;BR /&gt;IF(rank( sum(Cost), 4, 1) &amp;gt;= $(vSelectedRank) -2 and&lt;BR /&gt;rank( sum(Cost), 4, 1) &amp;lt;= $(vSelectedRank) +2&lt;BR /&gt;,&lt;BR /&gt;only(Project))&lt;BR /&gt;, Project)&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3. In the measure, I used the following:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;{1} sum(aggr( rank(Sum(Cost),4,1), Project))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And then I can see only 5 projects in the table after selecting &lt;span class="lia-unicode-emoji" title=":anguished_face:"&gt;😧&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Oleg_Troyansky_0-1748532887512.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/180896iF4A957104AE200D2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Oleg_Troyansky_0-1748532887512.png" alt="Oleg_Troyansky_0-1748532887512.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, this solution works well when one project is selected. With no selections, it only shows the first 3 projects. You'll need to add some conditions to overcome that. For example, you can have 2 variables - min and max, and compare your ranks to both of them. Then, you can capture all ranks between min-2 and max+2, and that should work universally.&lt;/P&gt;&lt;P&gt;Allow me to invite you to my training session on Set Analysis and AGGR() at the Masters Summit for Qlik in Hamburg or at my Qlik Expert Class in Vienna - see links in my signature.&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Oleg Troyansky&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 29 May 2025 15:37:38 GMT</pubDate>
    <dc:creator>Oleg_Troyansky</dc:creator>
    <dc:date>2025-05-29T15:37:38Z</dc:date>
    <item>
      <title>Filtering a selection by Rank</title>
      <link>https://community.qlik.com/t5/App-Development/Filtering-a-selection-by-Rank/m-p/2519487#M106269</link>
      <description>&lt;P&gt;Greetings All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've got a simple inline table which i can rank by cost in set analysis. Via set analysis and not script I'm trying to filter the table down to the selected dimension Project and the 2 rows above and beneath the current selection based on rank.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, in the table below I have the full table with Project and Cost being scripted and rank achieved by&amp;nbsp;&lt;/P&gt;&lt;P&gt;aggr(rank(sum(Cost),4,1), Project)&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Project&lt;/TD&gt;&lt;TD&gt;Cost&lt;/TD&gt;&lt;TD&gt;Rank&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;H&lt;/TD&gt;&lt;TD&gt;80&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;G&lt;/TD&gt;&lt;TD&gt;70&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;F&lt;/TD&gt;&lt;TD&gt;60&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;40&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;I&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Id like to achieve the following table if i select Project 'D' , the rest of the rows can be omitted&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Project&lt;/TD&gt;&lt;TD&gt;Cost&lt;/TD&gt;&lt;TD&gt;Rank&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;40&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;D&lt;/TD&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;E&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;I&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tried using the following&amp;nbsp;&lt;/P&gt;&lt;P&gt;If(Aggr(Rank(Sum({1} Cost), 1), Project) &amp;gt;=Only(TOTAL Aggr(Rank(TOTAL Sum({1&amp;lt;Project&amp;gt;} Amount)), Project))-2&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;Aggr(Rank(Sum({1} Amount), 1), Colour) &amp;lt;= Only(TOTAL Aggr(Rank(TOTAL Sum({1&amp;lt;Project&amp;gt;} Amount)), Project))+2, Project)&lt;/P&gt;&lt;P&gt;And this just moves the 'Project' to the top of the table and sort the other 'Projects ' alphabetically.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas anyone?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks in advance&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 May 2025 14:02:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Filtering-a-selection-by-Rank/m-p/2519487#M106269</guid>
      <dc:creator>lee_</dc:creator>
      <dc:date>2025-05-29T14:02:50Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering a selection by Rank</title>
      <link>https://community.qlik.com/t5/App-Development/Filtering-a-selection-by-Rank/m-p/2519497#M106270</link>
      <description>&lt;P&gt;Hi Lee,&lt;/P&gt;&lt;P&gt;Short of solving this tricky puzzle, I have some ideas for you to consider:&lt;/P&gt;&lt;P&gt;- Using Set Analysis {1} inside of an AGGR() wouldn't work as expected. You should populate the same set analysis at the AGGR level, like this:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Aggr({1}&amp;nbsp; Rank(TOTAL Sum({1} Amount)), Project)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- Disregarding Project selection within Set Analysis {1} is redundant - {1} ignores any selections&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- TOTAL within rank is only helpful with multiple dimensions, otherwise it's a moot point.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;For a while, I couldn't wrap my mind around this problem - how do I compare the global rankings with the rank of the selected project, and how do I cause the table to show all projects, despite the selection. I was about to suggest Alternate States, and then I actually found the solution. Here goes:&lt;BR /&gt;&lt;BR /&gt;1. I defined a variable vSelectedRank, to capture the value of the selected project's rank:&lt;BR /&gt;&lt;BR /&gt;=only({1 &amp;lt;Project=P({$} Project)&amp;gt;} AGGR( {1} rank(sum(Cost), 4, 1), Project) )&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2. Then, in the Dimension, I compare the ranks like this:&lt;BR /&gt;&lt;BR /&gt;={1} AGGR(&lt;BR /&gt;IF(rank( sum(Cost), 4, 1) &amp;gt;= $(vSelectedRank) -2 and&lt;BR /&gt;rank( sum(Cost), 4, 1) &amp;lt;= $(vSelectedRank) +2&lt;BR /&gt;,&lt;BR /&gt;only(Project))&lt;BR /&gt;, Project)&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3. In the measure, I used the following:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;{1} sum(aggr( rank(Sum(Cost),4,1), Project))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And then I can see only 5 projects in the table after selecting &lt;span class="lia-unicode-emoji" title=":anguished_face:"&gt;😧&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Oleg_Troyansky_0-1748532887512.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/180896iF4A957104AE200D2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Oleg_Troyansky_0-1748532887512.png" alt="Oleg_Troyansky_0-1748532887512.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now, this solution works well when one project is selected. With no selections, it only shows the first 3 projects. You'll need to add some conditions to overcome that. For example, you can have 2 variables - min and max, and compare your ranks to both of them. Then, you can capture all ranks between min-2 and max+2, and that should work universally.&lt;/P&gt;&lt;P&gt;Allow me to invite you to my training session on Set Analysis and AGGR() at the Masters Summit for Qlik in Hamburg or at my Qlik Expert Class in Vienna - see links in my signature.&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Oleg Troyansky&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 May 2025 15:37:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Filtering-a-selection-by-Rank/m-p/2519497#M106270</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2025-05-29T15:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering a selection by Rank</title>
      <link>https://community.qlik.com/t5/App-Development/Filtering-a-selection-by-Rank/m-p/2519503#M106274</link>
      <description>&lt;P&gt;Thank you Oleg -that's certainly put me on the right path&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ps I loved your book&lt;/P&gt;</description>
      <pubDate>Thu, 29 May 2025 16:11:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Filtering-a-selection-by-Rank/m-p/2519503#M106274</guid>
      <dc:creator>lee_</dc:creator>
      <dc:date>2025-05-29T16:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: Filtering a selection by Rank</title>
      <link>https://community.qlik.com/t5/App-Development/Filtering-a-selection-by-Rank/m-p/2519506#M106276</link>
      <description>&lt;P&gt;Thank you! It's so great to get feedback like this about my book!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Oleg&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 May 2025 16:58:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Filtering-a-selection-by-Rank/m-p/2519506#M106276</guid>
      <dc:creator>Oleg_Troyansky</dc:creator>
      <dc:date>2025-05-29T16:58:11Z</dc:date>
    </item>
  </channel>
</rss>

