<?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 Top n records of dimension parts in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Top-n-records-of-dimension-parts/m-p/325373#M707656</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All, I'm looking for a script function that will let me top n records of given dimension parts e.g. from the below set I'd like to load only John 54, John 21 and Mary 17, Mary 15.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;John, 54&lt;/P&gt;&lt;P&gt;Mary, 12&lt;/P&gt;&lt;P&gt;Mary, 17&lt;/P&gt;&lt;P&gt;John, 21,&lt;/P&gt;&lt;P&gt;John, 11&lt;/P&gt;&lt;P&gt;Mary, 15,&lt;/P&gt;&lt;P&gt;John, 7&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Przemek&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 16 Nov 2011 20:54:10 GMT</pubDate>
    <dc:creator />
    <dc:date>2011-11-16T20:54:10Z</dc:date>
    <item>
      <title>Top n records of dimension parts</title>
      <link>https://community.qlik.com/t5/QlikView/Top-n-records-of-dimension-parts/m-p/325373#M707656</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All, I'm looking for a script function that will let me top n records of given dimension parts e.g. from the below set I'd like to load only John 54, John 21 and Mary 17, Mary 15.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;John, 54&lt;/P&gt;&lt;P&gt;Mary, 12&lt;/P&gt;&lt;P&gt;Mary, 17&lt;/P&gt;&lt;P&gt;John, 21,&lt;/P&gt;&lt;P&gt;John, 11&lt;/P&gt;&lt;P&gt;Mary, 15,&lt;/P&gt;&lt;P&gt;John, 7&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Przemek&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2011 20:54:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Top-n-records-of-dimension-parts/m-p/325373#M707656</guid>
      <dc:creator />
      <dc:date>2011-11-16T20:54:10Z</dc:date>
    </item>
    <item>
      <title>Top n records of dimension parts</title>
      <link>https://community.qlik.com/t5/QlikView/Top-n-records-of-dimension-parts/m-p/325374#M707657</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Well, this is an example.&amp;nbsp; John W will argue again about the loop - but if you don't need top 100,000 you'll be fine &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data:&lt;BR /&gt;LOAD *INLINE [&lt;BR /&gt;Name, Age&lt;BR /&gt;John, 54&lt;BR /&gt;Mary, 12&lt;BR /&gt;Mary, 17&lt;BR /&gt;John, 21,&lt;BR /&gt;John, 11&lt;BR /&gt;Mary, 15,&lt;BR /&gt;John, 7];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FOR n=1 to 2&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;table:&lt;BR /&gt;LOAD&lt;BR /&gt; Name,&lt;BR /&gt; &lt;STRONG&gt;max(Age,$(n))&lt;/STRONG&gt; as TopAge&lt;BR /&gt;RESIDENT data&lt;BR /&gt;GROUP BY Name;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NEXT n&lt;BR /&gt;Drop Table data;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2011 21:24:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Top-n-records-of-dimension-parts/m-p/325374#M707657</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-11-16T21:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Top n records of dimension parts</title>
      <link>https://community.qlik.com/t5/QlikView/Top-n-records-of-dimension-parts/m-p/325375#M707658</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;Michael Solomovich wrote:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;John W will argue again about the loop - but if you don't need top 100,000 you'll be fine &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt;"&gt; &lt;/SPAN&gt; &lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;BR /&gt;Right on both counts!&amp;nbsp; I will argue that a loop is inefficient, but you're right that for low values of N you'll be fine. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I'm going to argue, though, I have to provide a non-looping alternative.&amp;nbsp; Here's one.&amp;nbsp; Script below, example attached.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Data:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;LOAD *&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;,recno() as ID&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;INLINE [&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Name, Value&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;John, 54&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Mary, 12&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Mary, 17&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;John, 21,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;John, 11&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Mary, 15,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;John, 7&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;];&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;LEFT JOIN (Data)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;LOAD&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;ID&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;,if(Name=previous(Name),peek(Count)+1,1) as Count&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;RESIDENT Data&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;ORDER BY Name, Value DESC&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;INNER JOIN (Data)&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;LOAD recno() as Count&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;AUTOGENERATE 2 // This is your N records.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;DROP FIELDS&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Count&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;,ID&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2011 21:49:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Top-n-records-of-dimension-parts/m-p/325375#M707658</guid>
      <dc:creator>johnw</dc:creator>
      <dc:date>2011-11-16T21:49:12Z</dc:date>
    </item>
  </channel>
</rss>

