<?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 Conditional Ranking in Script in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Conditional-Ranking-in-Script/m-p/1304519#M614654</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm facing a challenge with ranking hotels by spend. Attached is a sample data that I'm working on and the best solution that I came up with. I'm using AutoNumber() function to assign increasing values for each hotel in a market in a table sorted by spend in descending order. The issue that I'm running into is that if there are two hotels in the same market, AutoNumber assigns continuous numbering instead of skipping step for those instances where two hotels have same spend.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 908px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl65" height="32" style="font-size: 9pt; color: #333333; font-weight: bold; font-family: Arial, sans-serif; border: 0.5pt solid gainsboro; background: whitesmoke;" width="254"&gt;Market&lt;/TD&gt;&lt;TD class="xl66" style="font-size: 9pt; color: #333333; font-weight: bold; font-family: Arial, sans-serif; border: 0.5pt solid gainsboro; background: whitesmoke;" width="302"&gt;Hotel Name&lt;/TD&gt;&lt;TD class="xl66" style="font-size: 9pt; color: #333333; font-weight: bold; font-family: Arial, sans-serif; border: 0.5pt solid gainsboro; background: whitesmoke;" width="98"&gt;Spend&lt;/TD&gt;&lt;TD class="xl73" style="font-size: 9pt; color: #333333; font-weight: bold; font-family: Arial, sans-serif; border: 0.5pt solid gainsboro; background: whitesmoke;" width="84"&gt;Expression Rank&lt;/TD&gt;&lt;TD class="xl74" style="font-size: 9pt; color: #333333; font-weight: bold; font-family: Arial, sans-serif; border-top: 0.5pt solid gainsboro; border-right: none; border-bottom: 0.5pt solid gainsboro; border-left: 0.5pt solid gainsboro; background: whitesmoke;" width="93"&gt;Script AutoNumber&lt;/TD&gt;&lt;TD class="xl73" style="font-size: 9pt; color: #333333; font-weight: bold; font-family: Arial, sans-serif; border: 0.5pt solid gainsboro; background: whitesmoke;" width="77"&gt;Desired Rank&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl67" height="17" style="font-size: 9pt; color: #333333; font-family: Arial, sans-serif; border: 0.5pt solid gainsboro;"&gt;NAMER - UNITED STATES - FL - TAMPA&lt;/TD&gt;&lt;TD class="xl70" style="border-top: none; border-left: none;"&gt;HMPTN STE TAMPA YBOR CTY DNTWN&lt;/TD&gt;&lt;TD align="right" class="xl71" style="border-top: none; border-left: none;"&gt;270&lt;/TD&gt;&lt;TD class="xl68" style="border-top: none; border-left: none;"&gt;16-17&lt;/TD&gt;&lt;TD align="right" class="xl69" style="border-top: none; border-left: none;"&gt;16&lt;/TD&gt;&lt;TD align="right" class="xl69" style="font-size: 9pt; color: #9c0006; font-family: Arial, sans-serif; border: 0.5pt solid gainsboro; background: #ffc7ce;"&gt;16&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl67" height="17" style="font-size: 9pt; color: #333333; font-family: Arial, sans-serif; border: 0.5pt solid gainsboro;"&gt;NAMER - UNITED STATES - FL - TAMPA&lt;/TD&gt;&lt;TD class="xl70" style="border-top: none; border-left: none;"&gt;HOLIDAY INN EXP STES ROCKT PT&lt;/TD&gt;&lt;TD align="right" class="xl71" style="border-top: none; border-left: none;"&gt;270&lt;/TD&gt;&lt;TD class="xl68" style="border-top: none; border-left: none;"&gt;16-17&lt;/TD&gt;&lt;TD align="right" class="xl69" style="border-top: none; border-left: none;"&gt;17&lt;/TD&gt;&lt;TD align="right" class="xl69" style="font-size: 9pt; color: #9c0006; font-family: Arial, sans-serif; border: 0.5pt solid gainsboro; background: #ffc7ce;"&gt;16&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like both Hampton and Holiday Inn to be ranked 16, but both script and Rank expression function assign 16 and 17. Is there a way to assign same ranking if spend is the same?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mikhail B.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 27 Jul 2017 14:49:09 GMT</pubDate>
    <dc:creator>mbespartochnyy</dc:creator>
    <dc:date>2017-07-27T14:49:09Z</dc:date>
    <item>
      <title>Conditional Ranking in Script</title>
      <link>https://community.qlik.com/t5/QlikView/Conditional-Ranking-in-Script/m-p/1304519#M614654</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm facing a challenge with ranking hotels by spend. Attached is a sample data that I'm working on and the best solution that I came up with. I'm using AutoNumber() function to assign increasing values for each hotel in a market in a table sorted by spend in descending order. The issue that I'm running into is that if there are two hotels in the same market, AutoNumber assigns continuous numbering instead of skipping step for those instances where two hotels have same spend.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 908px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl65" height="32" style="font-size: 9pt; color: #333333; font-weight: bold; font-family: Arial, sans-serif; border: 0.5pt solid gainsboro; background: whitesmoke;" width="254"&gt;Market&lt;/TD&gt;&lt;TD class="xl66" style="font-size: 9pt; color: #333333; font-weight: bold; font-family: Arial, sans-serif; border: 0.5pt solid gainsboro; background: whitesmoke;" width="302"&gt;Hotel Name&lt;/TD&gt;&lt;TD class="xl66" style="font-size: 9pt; color: #333333; font-weight: bold; font-family: Arial, sans-serif; border: 0.5pt solid gainsboro; background: whitesmoke;" width="98"&gt;Spend&lt;/TD&gt;&lt;TD class="xl73" style="font-size: 9pt; color: #333333; font-weight: bold; font-family: Arial, sans-serif; border: 0.5pt solid gainsboro; background: whitesmoke;" width="84"&gt;Expression Rank&lt;/TD&gt;&lt;TD class="xl74" style="font-size: 9pt; color: #333333; font-weight: bold; font-family: Arial, sans-serif; border-top: 0.5pt solid gainsboro; border-right: none; border-bottom: 0.5pt solid gainsboro; border-left: 0.5pt solid gainsboro; background: whitesmoke;" width="93"&gt;Script AutoNumber&lt;/TD&gt;&lt;TD class="xl73" style="font-size: 9pt; color: #333333; font-weight: bold; font-family: Arial, sans-serif; border: 0.5pt solid gainsboro; background: whitesmoke;" width="77"&gt;Desired Rank&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl67" height="17" style="font-size: 9pt; color: #333333; font-family: Arial, sans-serif; border: 0.5pt solid gainsboro;"&gt;NAMER - UNITED STATES - FL - TAMPA&lt;/TD&gt;&lt;TD class="xl70" style="border-top: none; border-left: none;"&gt;HMPTN STE TAMPA YBOR CTY DNTWN&lt;/TD&gt;&lt;TD align="right" class="xl71" style="border-top: none; border-left: none;"&gt;270&lt;/TD&gt;&lt;TD class="xl68" style="border-top: none; border-left: none;"&gt;16-17&lt;/TD&gt;&lt;TD align="right" class="xl69" style="border-top: none; border-left: none;"&gt;16&lt;/TD&gt;&lt;TD align="right" class="xl69" style="font-size: 9pt; color: #9c0006; font-family: Arial, sans-serif; border: 0.5pt solid gainsboro; background: #ffc7ce;"&gt;16&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl67" height="17" style="font-size: 9pt; color: #333333; font-family: Arial, sans-serif; border: 0.5pt solid gainsboro;"&gt;NAMER - UNITED STATES - FL - TAMPA&lt;/TD&gt;&lt;TD class="xl70" style="border-top: none; border-left: none;"&gt;HOLIDAY INN EXP STES ROCKT PT&lt;/TD&gt;&lt;TD align="right" class="xl71" style="border-top: none; border-left: none;"&gt;270&lt;/TD&gt;&lt;TD class="xl68" style="border-top: none; border-left: none;"&gt;16-17&lt;/TD&gt;&lt;TD align="right" class="xl69" style="border-top: none; border-left: none;"&gt;17&lt;/TD&gt;&lt;TD align="right" class="xl69" style="font-size: 9pt; color: #9c0006; font-family: Arial, sans-serif; border: 0.5pt solid gainsboro; background: #ffc7ce;"&gt;16&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like both Hampton and Holiday Inn to be ranked 16, but both script and Rank expression function assign 16 and 17. Is there a way to assign same ranking if spend is the same?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mikhail B.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jul 2017 14:49:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Conditional-Ranking-in-Script/m-p/1304519#M614654</guid>
      <dc:creator>mbespartochnyy</dc:creator>
      <dc:date>2017-07-27T14:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Ranking in Script</title>
      <link>https://community.qlik.com/t5/QlikView/Conditional-Ranking-in-Script/m-p/1304520#M614655</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RankingPrep:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;LOAD Market, &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; NormName, &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Spend&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;FROM&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;[Ranking.xlsx]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;(ooxml, embedded labels, table is Sheet1);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Ranking:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;LOAD Market, &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; NormName, &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Spend,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #ff0000;"&gt;If(Market = Previous(Market), If(Spend = Previous(Spend), Peek('Rank'), RangeSum(Peek('Rank'), 1)), 1) as Rank,&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; AutoNumber(NormName, Market) as SpendRank&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Resident RankingPrep&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Order By Market, Spend desc;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DROP Table RankingPrep;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jul 2017 15:05:16 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Conditional-Ranking-in-Script/m-p/1304520#M614655</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2017-07-27T15:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Ranking in Script</title>
      <link>https://community.qlik.com/t5/QlikView/Conditional-Ranking-in-Script/m-p/1304521#M614656</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I had to chew on that for a bit to wrap my head around what happened, but I think I got it. I had no idea that Peek function can can be used to reference data that is not yet created and that it references previous row if row_no argument is not specified.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's how I read the logic:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Check, each line in a table if Market is the same, if it's not, you start with a rank of 1 because it's either the very first row of already correctly sorted table or it's a new Market (again in a sorted table).&lt;/LI&gt;&lt;LI&gt;If Market on a line is the same as Market on previous line, you check if spend is not the same. If it spend is not the same, you use RangeSum function to add rank from previous row (using Peek() function) to a 1.&lt;/LI&gt;&lt;LI&gt;If Market on a line is the same as Market on Previous line, and spend is same as spend on previous line, you select (using Peek() function) the rank from previous row.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks, Sunny!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mikhail B.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jul 2017 15:40:19 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Conditional-Ranking-in-Script/m-p/1304521#M614656</guid>
      <dc:creator>mbespartochnyy</dc:creator>
      <dc:date>2017-07-27T15:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Ranking in Script</title>
      <link>https://community.qlik.com/t5/QlikView/Conditional-Ranking-in-Script/m-p/1304522#M614657</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;
&lt;P&gt;Here's how I read the logic:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Check, each line in a table if Market is the same, if it's not, you start with a rank of 1 because it's either the very first row of already correctly sorted table or it's a new Market (again in a sorted table).&lt;/LI&gt;
&lt;LI&gt;If Market on a line is the same as Market on previous line, you check if spend is not the same. If it spend is not the same, you use RangeSum function to add rank from previous row (using Peek() function) to a 1.&lt;/LI&gt;
&lt;LI&gt;If Market on a line is the same as Market on Previous line, and spend is same as spend on previous line, you select (using Peek() function) the rank from previous row.&lt;/LI&gt;
&lt;/OL&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This is exactly what it is doing. and Peek/Previous approach is much better than using AutoNumber because AutoNumber drastically increase the reload time (don't know why)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jul 2017 15:44:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Conditional-Ranking-in-Script/m-p/1304522#M614657</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2017-07-27T15:44:28Z</dc:date>
    </item>
  </channel>
</rss>

