<?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: Load only first or last 5 in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Load-only-first-or-last-5/m-p/464987#M486709</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That indeed helps Juan Gerardo.&lt;/P&gt;&lt;P&gt;But if I do this, it suddenly count &lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;all &lt;/STRONG&gt;&lt;/SPAN&gt;DeliveryDates, instead of those belonging to each Customer? (all return value 5)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So how should I change this piece of code then?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;$(=if(count({&amp;lt;[Artikelidentification]={'Product X'}&amp;gt;} DeliveryDate)&amp;gt;5,5,count({&amp;lt;[Artikelidentification]={'Product X'}&amp;gt;} DeliveryDate)))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 21 Mar 2013 16:46:41 GMT</pubDate>
    <dc:creator />
    <dc:date>2013-03-21T16:46:41Z</dc:date>
    <item>
      <title>Load only first or last 5</title>
      <link>https://community.qlik.com/t5/QlikView/Load-only-first-or-last-5/m-p/464981#M486703</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my load script, I have the following code:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;IntervalProductX:&lt;/P&gt;&lt;P&gt;Load Customer, DeliveryDate&lt;/P&gt;&lt;P&gt;,if(peek(Customer)=Customer,-peek(DeliveryDate)+DeliveryDate) as Interval&lt;/P&gt;&lt;P&gt;resident CustomersDB &lt;/P&gt;&lt;P&gt;where Artikelidentification = 'PRODUCT X'&lt;/P&gt;&lt;P&gt;order by Customer, DeliveryDate;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This creates an Interval of the DeliveryDate per customer who gets Product X delivered.&lt;/P&gt;&lt;P&gt;(If necessary I can add asc / desc behind the order by, so it could be first or last 5)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I would like to show in a straight table, the average Interval per Customer over the last 5 DeliveryDate (1-5).&lt;/P&gt;&lt;P&gt;And in a second column with the avarage over DeliveryDate 6-15.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I calculate this in an expression or in the load script?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I use the above code with "First 5" before it and order it by desc, it doesn't load the first 5 from each customer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the straight table should look like&lt;/P&gt;&lt;TABLE border="1" cellpadding="3" cellspacing="0" class="jiveBorder" style="width: 100%; border: 1px solid #000000;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;Customer&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;Avg Interval&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="text-align: center;"&gt;Customer X&lt;/TD&gt;&lt;TD style="text-align: center;"&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Customer Y&lt;/TD&gt;&lt;TD style="text-align: center;"&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; (don't need the dates, just the avarage of those last 5 Intervals)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope my question is clear.&lt;/P&gt;&lt;P&gt;Could someone help me with this?&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;Willem&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Mar 2013 11:02:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Load-only-first-or-last-5/m-p/464981#M486703</guid>
      <dc:creator />
      <dc:date>2013-03-21T11:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: Load only first or last 5</title>
      <link>https://community.qlik.com/t5/QlikView/Load-only-first-or-last-5/m-p/464982#M486704</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I suggest you use the Class() function in a calculated dimension. It should be something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Class(Interval, 5, 'DeliveryDate')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Even you can make the interval range dynamic, if you use a variable instead of a fixed 5.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Juan Gerardo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Mar 2013 13:05:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Load-only-first-or-last-5/m-p/464982#M486704</guid>
      <dc:creator />
      <dc:date>2013-03-21T13:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: Load only first or last 5</title>
      <link>https://community.qlik.com/t5/QlikView/Load-only-first-or-last-5/m-p/464983#M486705</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your reply Juan Gerardo Cabeza.&lt;/P&gt;&lt;P&gt;I don't see how I could implement this in my scenario.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm creating a straight table with the following fields:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"Customer", "MaxDeliveryDate", "Avg Interval over last 5 delivery dates" and a few more fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;there are about 120 customers in this table.&lt;/P&gt;&lt;P&gt;I would like to see if their average interval over the last 5 delivery dates, change in comparison of the avg interval over the 10 delivery dates before them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I use the expression avg(Interval), the average interval over all the delivery dates is taken, but some order for more then 3 years.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't yet see how this class code could help me with this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since I can calculate per customer what their 5th last delivery date was, I was thinking about an expression like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;=if((DeliveryDate)&amp;gt;FirstSortedValue(DeliveryDate, -DeliveryDate,5),avg(Interval))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But this comes up with nothing.&lt;/P&gt;&lt;P&gt;Plus that if it's a new customer who only has 3 DeliveryDates yet, the firstsortedvalue returns "-" (it doesn't exists yet)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hopefully I made myself more clear, or maybe your way is the right way, but you could explain it a little more to me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Mar 2013 13:23:49 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Load-only-first-or-last-5/m-p/464983#M486705</guid>
      <dc:creator />
      <dc:date>2013-03-21T13:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: Load only first or last 5</title>
      <link>https://community.qlik.com/t5/QlikView/Load-only-first-or-last-5/m-p/464984#M486706</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have to use the Class() function as a Calculated Dimension, not expression. Maybe if you can attach some example qlikview I can have a look, and show you how to do it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Mar 2013 13:27:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Load-only-first-or-last-5/m-p/464984#M486706</guid>
      <dc:creator />
      <dc:date>2013-03-21T13:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Load only first or last 5</title>
      <link>https://community.qlik.com/t5/QlikView/Load-only-first-or-last-5/m-p/464985#M486707</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is was a calculated dimension, I am aware of.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I almost got it working I think.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only thing is, is it possible to add a calculated value behind the FirstSortedValue (the &lt;N&gt;?&lt;/N&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I got a piece of code which calculates if the number "5" is there. If so, the number 5 is filled in, if there are only for example 3 DeliveryDates, it fills in 3. But I can't get that piece of code implemented in this FirstSortedValue&lt;/P&gt;&lt;P&gt;So the following piece should be editted:&lt;/P&gt;&lt;P&gt;FirstSortedValue(DeliveryDate, -DeliveryDate,&lt;STRONG style="text-decoration: underline;"&gt;5&lt;/STRONG&gt;)&lt;/P&gt;&lt;P&gt;to for example&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FirstSortedValue(DeliveryDate, -DeliveryDate,&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if(count({&amp;lt;[Artikelidentification]={'Product X'}&amp;gt;} DeliveryDate)&amp;gt;5,5,count({&amp;lt;[Artikelidentification]={'Product X'}&amp;gt;} DeliveryDate))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I get this to work, I can calculate the average interval over the last 5 dates.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So how can I replace the &lt;N&gt; in the FirstSortedValue with a calculation?&lt;/N&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Mar 2013 15:13:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Load-only-first-or-last-5/m-p/464985#M486707</guid>
      <dc:creator />
      <dc:date>2013-03-21T15:13:17Z</dc:date>
    </item>
    <item>
      <title>Re: Load only first or last 5</title>
      <link>https://community.qlik.com/t5/QlikView/Load-only-first-or-last-5/m-p/464986#M486708</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try using dollar expansion. Maybe:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff; color: #737373; font-family: Arial;"&gt;FirstSortedValue(DeliveryDate, -DeliveryDate,&lt;/P&gt;&lt;P style="background-color: #ffffff; color: #737373; font-family: Arial;"&gt;&lt;STRONG&gt;$(=&lt;/STRONG&gt;if(count({&amp;lt;[Artikelidentification]={'Product X'}&amp;gt;} DeliveryDate)&amp;gt;5,5,count({&amp;lt;[Artikelidentification]={'Product X'}&amp;gt;} DeliveryDate)&lt;STRONG&gt;)&lt;/STRONG&gt;)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Mar 2013 16:20:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Load-only-first-or-last-5/m-p/464986#M486708</guid>
      <dc:creator />
      <dc:date>2013-03-21T16:20:32Z</dc:date>
    </item>
    <item>
      <title>Re: Load only first or last 5</title>
      <link>https://community.qlik.com/t5/QlikView/Load-only-first-or-last-5/m-p/464987#M486709</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That indeed helps Juan Gerardo.&lt;/P&gt;&lt;P&gt;But if I do this, it suddenly count &lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;all &lt;/STRONG&gt;&lt;/SPAN&gt;DeliveryDates, instead of those belonging to each Customer? (all return value 5)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So how should I change this piece of code then?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;$(=if(count({&amp;lt;[Artikelidentification]={'Product X'}&amp;gt;} DeliveryDate)&amp;gt;5,5,count({&amp;lt;[Artikelidentification]={'Product X'}&amp;gt;} DeliveryDate)))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Mar 2013 16:46:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Load-only-first-or-last-5/m-p/464987#M486709</guid>
      <dc:creator />
      <dc:date>2013-03-21T16:46:41Z</dc:date>
    </item>
  </channel>
</rss>

