<?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: Nprinting PixelPerfect Ranking with set analysis and aggr() in Qlik NPrinting</title>
    <link>https://community.qlik.com/t5/Qlik-NPrinting/Nprinting-PixelPerfect-Ranking-with-set-analysis-and-aggr/m-p/1660002#M27478</link>
    <description>&lt;P&gt;Like I mentioned before I am not sure about your aggr function, but i did some quick test and this is what formula I would use:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If(count(distinct saleId)=0,0,&lt;/SPAN&gt;&lt;SPAN&gt;rank(count(distinct {&amp;lt;restaurantId=&amp;gt;} saleId)/sum( {&amp;lt;restaurantId=&amp;gt;} aggr([Guest Counts],restaurantId,Date))))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;the reason for Ïf statement"--&amp;gt; If(count(distinct saleId)=0,0.... is to hide rows which will allways produce data once you start cycling over restaurantid field.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;btw - why do you need to use aggr fuction? Cant you just use sum([Guest Counts]) in second part of your expression?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 22 Dec 2019 22:31:12 GMT</pubDate>
    <dc:creator>Lech_Miszkiewicz</dc:creator>
    <dc:date>2019-12-22T22:31:12Z</dc:date>
    <item>
      <title>Nprinting PixelPerfect Ranking with set analysis and aggr()</title>
      <link>https://community.qlik.com/t5/Qlik-NPrinting/Nprinting-PixelPerfect-Ranking-with-set-analysis-and-aggr/m-p/1659769#M27476</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;Currently, I am trying to get a ranking calculation done in QS so I can use it for my Nprinting report.&lt;BR /&gt;The ranking checks the % Sales Performance for every month compared to the other restaurants.&lt;BR /&gt;When I try this with the rank() function, I am not achieving the desired result. I tried set analysis and aggr () but think that I am doing something wrong.&lt;/P&gt;&lt;P&gt;I was looking at the following post, which is of someone with more or less the same issue.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.qlik.com/t5/Qlik-NPrinting-Discussions/Nprinting-report-rank-with-filter/m-p/1659734#M27475" target="_blank"&gt;https://community.qlik.com/t5/Qlik-NPrinting-Discussions/Nprinting-report-rank-with-filter/m-p/1659734#M27475&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Please help me find the correct calculation.&lt;/P&gt;&lt;P&gt;What I have in QS with NO SELECTIONS:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;YearMonth&lt;/TD&gt;&lt;TD&gt;restaurantId&lt;/TD&gt;&lt;TD&gt;Sales&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;% Sales performance&lt;BR /&gt;(Sales/other platform Sales)&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;(Rank)&amp;nbsp;&lt;BR /&gt;&lt;/FONT&gt;&lt;FONT color="#FF0000"&gt;based on % Sales perf&lt;/FONT&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;201910&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;20%&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;2&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;201910&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;156&lt;/TD&gt;&lt;TD&gt;24%&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&g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t;&lt;TD&gt;140&lt;/TD&gt;&lt;TD&gt;20%&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;2&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;201912&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;3&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;160&lt;/TD&gt;&lt;TD&gt;23%&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the calculation for % Sales:&lt;BR /&gt;count(distinct saleId)/sum(aggr([Guest Counts],restaurantId,Date))&lt;/P&gt;&lt;P&gt;For rank:&lt;BR /&gt;rank(count(distinct saleId)/sum(aggr([Guest Counts],restaurantId,Date)))&lt;/P&gt;&lt;P&gt;When I select a restaurant:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;YearMonth&lt;/TD&gt;&lt;TD&gt;restaurantId&lt;/TD&gt;&lt;TD&gt;Sales&lt;/TD&gt;&lt;TD&gt;% Sales&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;Rank&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;201910&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;20%&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;201911&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;150&lt;/TD&gt;&lt;TD&gt;24%&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;201912&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;120&lt;/TD&gt;&lt;TD&gt;18%&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IDEALLY, I would get the following when selecting a restaurant:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;YearMonth&lt;/TD&gt;&lt;TD&gt;restaurantId&lt;/TD&gt;&lt;TD&gt;Sales&lt;/TD&gt;&lt;TD&gt;% Sales&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#008000"&gt;Rank&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;201910&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;20%&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#008000"&gt;2&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;201911&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;150&lt;/TD&gt;&lt;TD&gt;24%&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#008000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;201912&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;120&lt;/TD&gt;&lt;TD&gt;18%&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#008000"&gt;3&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Where rank is still following the benchmarking(%Sales). (In a bigger dataset it might happen there is no rank 1 when selecting a restaurant)&lt;BR /&gt;&lt;BR /&gt;In NPrinting, I have the same table that I need to build.&lt;BR /&gt;My report is in a cycle by restaurantId and in the template, the table is inside a YearMonth level.&lt;BR /&gt;&lt;BR /&gt;Hopefully, someone can help me find the set analysis/aggr() that I need to use because I can't seem to find it.&lt;/P&gt;&lt;P&gt;Below a screenshot of the part of the model that is being used.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot_1.png" style="width: 530px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/25855i90BCE01B453D512E/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot_1.png" alt="Screenshot_1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2019 13:06:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Qlik-NPrinting/Nprinting-PixelPerfect-Ranking-with-set-analysis-and-aggr/m-p/1659769#M27476</guid>
      <dc:creator>lorevanachter</dc:creator>
      <dc:date>2019-12-20T13:06:27Z</dc:date>
    </item>
    <item>
      <title>Re: Nprinting PixelPerfect Ranking with set analysis and aggr()</title>
      <link>https://community.qlik.com/t5/Qlik-NPrinting/Nprinting-PixelPerfect-Ranking-with-set-analysis-and-aggr/m-p/1660002#M27478</link>
      <description>&lt;P&gt;Like I mentioned before I am not sure about your aggr function, but i did some quick test and this is what formula I would use:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If(count(distinct saleId)=0,0,&lt;/SPAN&gt;&lt;SPAN&gt;rank(count(distinct {&amp;lt;restaurantId=&amp;gt;} saleId)/sum( {&amp;lt;restaurantId=&amp;gt;} aggr([Guest Counts],restaurantId,Date))))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;the reason for Ïf statement"--&amp;gt; If(count(distinct saleId)=0,0.... is to hide rows which will allways produce data once you start cycling over restaurantid field.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;btw - why do you need to use aggr fuction? Cant you just use sum([Guest Counts]) in second part of your expression?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Dec 2019 22:31:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Qlik-NPrinting/Nprinting-PixelPerfect-Ranking-with-set-analysis-and-aggr/m-p/1660002#M27478</guid>
      <dc:creator>Lech_Miszkiewicz</dc:creator>
      <dc:date>2019-12-22T22:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: Nprinting PixelPerfect Ranking with set analysis and aggr()</title>
      <link>https://community.qlik.com/t5/Qlik-NPrinting/Nprinting-PixelPerfect-Ranking-with-set-analysis-and-aggr/m-p/1665046#M27594</link>
      <description>&lt;P&gt;Thank you for your help&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/1326"&gt;@Lech_Miszkiewicz&lt;/a&gt;&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The weird aggregation is because these numbers are provided on a different aggregation level than the other calculation (count distinct). Even though the calculate the same thing for different sources.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Apart from that, my coworker eventually found the solution. I will post it in a different reply to have a clear solution post. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 13:31:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Qlik-NPrinting/Nprinting-PixelPerfect-Ranking-with-set-analysis-and-aggr/m-p/1665046#M27594</guid>
      <dc:creator>lorevanachter</dc:creator>
      <dc:date>2020-01-13T13:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: Nprinting PixelPerfect Ranking with set analysis and aggr()</title>
      <link>https://community.qlik.com/t5/Qlik-NPrinting/Nprinting-PixelPerfect-Ranking-with-set-analysis-and-aggr/m-p/1665106#M27595</link>
      <description>&lt;P&gt;Replying to my own post as my coworker found the solution.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The ranking seemed very difficult, if not impossible, to try and solve in the frontend, so we decided to get back to the script and statically calculate the ranking on the aggregation level needed. This way we can be sure that the ranking is not variable to selections made in the dashboard.&lt;/P&gt;&lt;P&gt;Hereby the sample code used:&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;Table1:
load * inline
[YearMonth, restaurantId, restaurantName, Sales, %Sales
201910,1,A,123,0.2
201910,2,B,156,0.24
201910,3,C,188,0.18
201911,1,A,150,0.24
201911,2,B,160,0.23
201911,3,C,170,0.20
201912,1,A,120,0.18
201912,2,B,140,0.20
201912,3,C,160,0.23
];

temp:
NoConcatenate
load *,
	
	if(isnull(peek(YearMonth)),1,
    	if(previous(YearMonth)=YearMonth,peek(Ranking)+1,1)) as Ranking
    resident Table1
    order by YearMonth, %Sales desc;
    drop table Table1;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 15:37:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Qlik-NPrinting/Nprinting-PixelPerfect-Ranking-with-set-analysis-and-aggr/m-p/1665106#M27595</guid>
      <dc:creator>lorevanachter</dc:creator>
      <dc:date>2020-01-13T15:37:56Z</dc:date>
    </item>
  </channel>
</rss>

