<?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: Calculate average on subset of records. in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Calculate-average-on-subset-of-records/m-p/735723#M10609</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok, it's pretty simple. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let's say we have the following values and I want to calculate the average on the worst 10% of values.&lt;/P&gt;&lt;P&gt;Id, value&lt;/P&gt;&lt;P&gt;1, 55&lt;/P&gt;&lt;P&gt;2, 45&lt;/P&gt;&lt;P&gt;3, 48&lt;/P&gt;&lt;P&gt;4, 64&lt;/P&gt;&lt;P&gt;5, 65&lt;/P&gt;&lt;P&gt;6, 39&lt;/P&gt;&lt;P&gt;7, 42&lt;/P&gt;&lt;P&gt;8, 51&lt;/P&gt;&lt;P&gt;9, 61&lt;/P&gt;&lt;P&gt;10, 52&lt;/P&gt;&lt;P&gt;11, 53&lt;/P&gt;&lt;P&gt;12, 70&lt;/P&gt;&lt;P&gt;13, 68&lt;/P&gt;&lt;P&gt;14, 59&lt;/P&gt;&lt;P&gt;15, 55&lt;/P&gt;&lt;P&gt;16, 50&lt;/P&gt;&lt;P&gt;17, 49&lt;/P&gt;&lt;P&gt;18, 40&lt;/P&gt;&lt;P&gt;19, 51&lt;/P&gt;&lt;P&gt;20, 63&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The desired result is then 39.5, since the worst 10% of values are 39 and 40. For 5% the result will be 39 and for 20% the result 41.5.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this example made my question more clear.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/Viktor&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 02 Oct 2014 06:56:08 GMT</pubDate>
    <dc:creator />
    <dc:date>2014-10-02T06:56:08Z</dc:date>
    <item>
      <title>Calculate average on subset of records.</title>
      <link>https://community.qlik.com/t5/App-Development/Calculate-average-on-subset-of-records/m-p/735721#M10607</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;I'm new to Qlik and its' scripting language and I'm stuck on a seamingly simple task: To create an average, but only include the lowest 5% of the values. &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;The following is a javascript implementation I'm currently using:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;// Sort the values&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;data = _.sortBy(data, alertness);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Pick out the worst 5 percent of alertness values into new array&lt;/P&gt;&lt;P&gt;var worst5percent = _.first(data, Math.round(data.length * 0.05));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// Reduce the sum and divide by array length.&lt;/P&gt;&lt;P&gt;var pa5 = _.reduce(_.pluck(worst5percent, alertness), function (result, num) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return result + num;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }, 0) / worst5percent.length;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically I need to sort, top and average, but I cannot seem to find a sort method. What can I do to achieve this result?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/Viktor&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Oct 2014 12:48:01 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculate-average-on-subset-of-records/m-p/735721#M10607</guid>
      <dc:creator />
      <dc:date>2014-10-01T12:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average on subset of records.</title>
      <link>https://community.qlik.com/t5/App-Development/Calculate-average-on-subset-of-records/m-p/735722#M10608</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Victor,&amp;nbsp; do you have some data to play with ? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In Sense the rank() and firstsortedvalue() functions can help with sorting and there is the ability to do nested aggregations using&amp;nbsp; aggr().&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you have a small sample of data and your desired result, kindly post and we'll get you started.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 Oct 2014 17:35:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculate-average-on-subset-of-records/m-p/735722#M10608</guid>
      <dc:creator>JonnyPoole</dc:creator>
      <dc:date>2014-10-01T17:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average on subset of records.</title>
      <link>https://community.qlik.com/t5/App-Development/Calculate-average-on-subset-of-records/m-p/735723#M10609</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok, it's pretty simple. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let's say we have the following values and I want to calculate the average on the worst 10% of values.&lt;/P&gt;&lt;P&gt;Id, value&lt;/P&gt;&lt;P&gt;1, 55&lt;/P&gt;&lt;P&gt;2, 45&lt;/P&gt;&lt;P&gt;3, 48&lt;/P&gt;&lt;P&gt;4, 64&lt;/P&gt;&lt;P&gt;5, 65&lt;/P&gt;&lt;P&gt;6, 39&lt;/P&gt;&lt;P&gt;7, 42&lt;/P&gt;&lt;P&gt;8, 51&lt;/P&gt;&lt;P&gt;9, 61&lt;/P&gt;&lt;P&gt;10, 52&lt;/P&gt;&lt;P&gt;11, 53&lt;/P&gt;&lt;P&gt;12, 70&lt;/P&gt;&lt;P&gt;13, 68&lt;/P&gt;&lt;P&gt;14, 59&lt;/P&gt;&lt;P&gt;15, 55&lt;/P&gt;&lt;P&gt;16, 50&lt;/P&gt;&lt;P&gt;17, 49&lt;/P&gt;&lt;P&gt;18, 40&lt;/P&gt;&lt;P&gt;19, 51&lt;/P&gt;&lt;P&gt;20, 63&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The desired result is then 39.5, since the worst 10% of values are 39 and 40. For 5% the result will be 39 and for 20% the result 41.5.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this example made my question more clear.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/Viktor&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Oct 2014 06:56:08 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculate-average-on-subset-of-records/m-p/735723#M10609</guid>
      <dc:creator />
      <dc:date>2014-10-02T06:56:08Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average on subset of records.</title>
      <link>https://community.qlik.com/t5/App-Development/Calculate-average-on-subset-of-records/m-p/735724#M10610</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think this expression (in a textbox or chart without dim)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;avg(aggr(&lt;/P&gt;&lt;P&gt;&amp;nbsp; if(value &amp;lt; Fractile(TOTAL value, 0.2), value), &lt;/P&gt;&lt;P&gt;&amp;nbsp; Id))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;replace 0.2 with 0.1, 0.05 or better with a variable&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Oct 2014 07:37:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Calculate-average-on-subset-of-records/m-p/735724#M10610</guid>
      <dc:creator>maxgro</dc:creator>
      <dc:date>2014-10-02T07:37:21Z</dc:date>
    </item>
  </channel>
</rss>

