<?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: Need help with a summation problem in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Need-help-with-a-summation-problem/m-p/256633#M498384</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Magnus,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try this for your expression:&lt;/P&gt;&lt;P&gt;=IF(Largestclientrow=10,&lt;/P&gt;&lt;P&gt;max(aggr(sum(hours),Client,Largestclient),1)&lt;/P&gt;&lt;P&gt;,&lt;/P&gt;&lt;P&gt;IF(Largestclientrow=20,&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;sum(aggr(if(rank(sum(Amount),4)&amp;lt;=5,sum(hours)),Largestclient,Client))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF(Largestclientrow=40,&lt;/P&gt;&lt;P&gt;sum(hours)&lt;/P&gt;&lt;P&gt;)))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could reuse the same expression to calculate your other TopX values, too, just replace the &amp;lt;=5 with =1 or &amp;lt;=40&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Stefan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;P.S. just saw Lasses solution, which probably works fine. Only disadvantage with FirstSortedValue is, that it is returning NULL if more than one value of expression share the same lowest sort-order.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;edit&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 13 Sep 2011 09:34:59 GMT</pubDate>
    <dc:creator>swuehl</dc:creator>
    <dc:date>2011-09-13T09:34:59Z</dc:date>
    <item>
      <title>Need help with a summation problem</title>
      <link>https://community.qlik.com/t5/QlikView/Need-help-with-a-summation-problem/m-p/256631#M498382</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;I would like to have a object with two columns the first showing amount and the second showing hours.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the first row I want to show our largest client and in the second row I would like to show the total sum of our 5 largest clients. My problem is that I want both columns to be sorted on the amount. Both columns should show the sum of the 5 largest clients ranked on the amount.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN id="result_box" lang="en"&gt;&lt;SPAN class="hps"&gt;In&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;the attached&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;example &lt;/SPAN&gt;the column with the hours shows the &lt;SPAN class="hps"&gt;wrong&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;value&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;because it&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;takes&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;the five&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;largest&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;clients&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;sorted&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;in&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;hours instead of&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;value.&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;for the five largest&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;clients&lt;/SPAN&gt; it &lt;SPAN class="hps"&gt;summarizes&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;to &lt;/SPAN&gt;&lt;SPAN class="hps"&gt;280 hours&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;but I&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;want it to&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;add up&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;to 240&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;hours.&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;how&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;do I do&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;if I&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;want it to be&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;sort&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;of&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;the five&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;largest&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;clients&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;in terms of&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;value&lt;/SPAN&gt; &lt;SPAN class="hps"&gt;insted of&lt;/SPAN&gt;&lt;SPAN class="hps"&gt; of hours&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks in advance&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Magnus&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Sep 2011 08:56:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Need-help-with-a-summation-problem/m-p/256631#M498382</guid>
      <dc:creator />
      <dc:date>2011-09-13T08:56:24Z</dc:date>
    </item>
    <item>
      <title>Need help with a summation problem</title>
      <link>https://community.qlik.com/t5/QlikView/Need-help-with-a-summation-problem/m-p/256632#M498383</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you can use FirstSortedValue:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;IF(Largestclientrow=10,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FirstSortedValue(hours,-Amount,1)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;IF(Largestclientrow=20,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FirstSortedValue(hours,-Amount,1)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+FirstSortedValue(hours,-Amount,2)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+FirstSortedValue(hours,-Amount,3)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+FirstSortedValue(hours,-Amount,4)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;+FirstSortedValue(hours,-Amount,5)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;IF(Largestclientrow=40,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;sum(hours)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;)))&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BR&lt;/P&gt;&lt;P&gt;Lasse&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Sep 2011 09:25:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Need-help-with-a-summation-problem/m-p/256632#M498383</guid>
      <dc:creator>lkallioniemi</dc:creator>
      <dc:date>2011-09-13T09:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with a summation problem</title>
      <link>https://community.qlik.com/t5/QlikView/Need-help-with-a-summation-problem/m-p/256633#M498384</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Magnus,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try this for your expression:&lt;/P&gt;&lt;P&gt;=IF(Largestclientrow=10,&lt;/P&gt;&lt;P&gt;max(aggr(sum(hours),Client,Largestclient),1)&lt;/P&gt;&lt;P&gt;,&lt;/P&gt;&lt;P&gt;IF(Largestclientrow=20,&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;sum(aggr(if(rank(sum(Amount),4)&amp;lt;=5,sum(hours)),Largestclient,Client))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF(Largestclientrow=40,&lt;/P&gt;&lt;P&gt;sum(hours)&lt;/P&gt;&lt;P&gt;)))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could reuse the same expression to calculate your other TopX values, too, just replace the &amp;lt;=5 with =1 or &amp;lt;=40&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Stefan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;P.S. just saw Lasses solution, which probably works fine. Only disadvantage with FirstSortedValue is, that it is returning NULL if more than one value of expression share the same lowest sort-order.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;edit&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Sep 2011 09:34:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Need-help-with-a-summation-problem/m-p/256633#M498384</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2011-09-13T09:34:59Z</dc:date>
    </item>
    <item>
      <title>Need help with a summation problem</title>
      <link>https://community.qlik.com/t5/QlikView/Need-help-with-a-summation-problem/m-p/256634#M498385</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Lasse an Swuehl&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is working perfect!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Sep 2011 09:48:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Need-help-with-a-summation-problem/m-p/256634#M498385</guid>
      <dc:creator />
      <dc:date>2011-09-13T09:48:22Z</dc:date>
    </item>
  </channel>
</rss>

