<?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 on a nested aggregation in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/need-help-on-a-nested-aggregation/m-p/675532#M245255</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For nested aggregations you need to use the aggr function:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;avg(aggr( RangeMin (SALE, avg(SALE) + Stdev(SALE))),country))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;But since country is a group and not a field you need to use the getcurrentfield function:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;avg(aggr( RangeMin (SALE, avg(SALE) + Stdev(SALE))), $(=getcurrentfield[country])) ))&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 13 Jun 2014 09:20:15 GMT</pubDate>
    <dc:creator>Gysbert_Wassenaar</dc:creator>
    <dc:date>2014-06-13T09:20:15Z</dc:date>
    <item>
      <title>need help on a nested aggregation</title>
      <link>https://community.qlik.com/t5/QlikView/need-help-on-a-nested-aggregation/m-p/675531#M245254</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 need some help for an expression involving nested aggregation.&lt;/P&gt;&lt;P&gt;I have some sale data with sales for different countries. Fields are COUNTRY and SALE&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am building a straight table graph&amp;nbsp; with average sales per country. No Pb. Dimension is COUNTRY and expressions are :&lt;/P&gt;&lt;P&gt;* AVG_SALE = avg(sale)&lt;/P&gt;&lt;P&gt;* STDEV_SALE = stdev(sale)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;output then looks like&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;country&amp;nbsp;&amp;nbsp;&amp;nbsp; avg_sale&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stdev_sale&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;FR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;UK&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 15&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I need to add a column CAP_AVG_SALE that would display the average of sales capped to (avg_sale+stdev_sale) per country, i.e if sale value exceeds the average+standard deviation for the country, we retain (avg_sale+stdev_sale). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The output should then look like&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;country&amp;nbsp;&amp;nbsp;&amp;nbsp; avg_sale&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stdev_sale&amp;nbsp;&amp;nbsp; cap_avg_sale&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;FR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11.7&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;UK&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 15&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 14.6&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My first try was to use an expression like &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;avg( RangeMin (SALE, avg(TOTAL SALE) + Stdev(TOTAL SALE)))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The problem with this is that the TOTAL is applied on the COUNTRY dimension so the average avg(TOTAL SALE) is the global average, but what I need in the nested avg() is the average per country&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I would need something more like &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;avg( RangeMin (SALE, avg({&amp;lt;COUNTRY={current country in the table row}&amp;gt;} TOTAL SALE) + Stdev({&amp;lt;COUNTRY={current country in the table row}&amp;gt;} TOTAL SALE)))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;right now I cannot fin a formula to get the country from the current table row so I'm a bit stuck&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so my question is :&lt;/P&gt;&lt;P&gt;1) Is there maybe a staistical function that I could use and does exactly what I need so I don't need to do these nested aggregations ?&lt;/P&gt;&lt;P&gt;2) if not, which expression could you advise ?&lt;/P&gt;&lt;P&gt;3) In my actual graph, COUNTRY is actually a dimension group. Hopefully the solution should also work with that&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks a lot&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Philippe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 09:07:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/need-help-on-a-nested-aggregation/m-p/675531#M245254</guid>
      <dc:creator />
      <dc:date>2014-06-13T09:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: need help on a nested aggregation</title>
      <link>https://community.qlik.com/t5/QlikView/need-help-on-a-nested-aggregation/m-p/675532#M245255</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;For nested aggregations you need to use the aggr function:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;avg(aggr( RangeMin (SALE, avg(SALE) + Stdev(SALE))),country))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;But since country is a group and not a field you need to use the getcurrentfield function:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;avg(aggr( RangeMin (SALE, avg(SALE) + Stdev(SALE))), $(=getcurrentfield[country])) ))&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 09:20:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/need-help-on-a-nested-aggregation/m-p/675532#M245255</guid>
      <dc:creator>Gysbert_Wassenaar</dc:creator>
      <dc:date>2014-06-13T09:20:15Z</dc:date>
    </item>
    <item>
      <title>Re: need help on a nested aggregation</title>
      <link>https://community.qlik.com/t5/QlikView/need-help-on-a-nested-aggregation/m-p/675533#M245256</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Gysbert,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks for the prompt answer, unfortunately it doesn't behave as expected : the expression output is the addition of avg_sale+stdev_sale. I think it's because the SALE that is compared to avg(SALE) in the RangeMin() is inside the aggr() ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So it seems we would like to use the aggr() only for the inner avg() and stdev() like in&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;avg(RangeMin (sale, aggr(avg(sale) + Stdev(sale), country)))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;which doesn't work because I think the aggr is an internal table of several lines when we need one line for the current country, hence my first idea of a set analysis ....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I enclose a basic test projet&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;best regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Phlippe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 12:47:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/need-help-on-a-nested-aggregation/m-p/675533#M245256</guid>
      <dc:creator />
      <dc:date>2014-06-13T12:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: Re: need help on a nested aggregation</title>
      <link>https://community.qlik.com/t5/QlikView/need-help-on-a-nested-aggregation/m-p/675534#M245257</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just to check, can you take a look at the second (lower) straight table in the attached qvw. Are the cap_stdev_sale values in that chart correct?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 13:10:16 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/need-help-on-a-nested-aggregation/m-p/675534#M245257</guid>
      <dc:creator>Gysbert_Wassenaar</dc:creator>
      <dc:date>2014-06-13T13:10:16Z</dc:date>
    </item>
    <item>
      <title>Re: need help on a nested aggregation</title>
      <link>https://community.qlik.com/t5/QlikView/need-help-on-a-nested-aggregation/m-p/675535#M245258</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;here is the file with the correct values. I have modified slightly the data samples as there were duplicates, and have modified your join which was a full cartesian&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 14:02:01 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/need-help-on-a-nested-aggregation/m-p/675535#M245258</guid>
      <dc:creator />
      <dc:date>2014-06-13T14:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: need help on a nested aggregation</title>
      <link>https://community.qlik.com/t5/QlikView/need-help-on-a-nested-aggregation/m-p/675536#M245259</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok, in case you want to do this without precalculating averages and stdevs in the script you can try this expression: avg(aggr(rangemin(only(sale),avg(total &amp;lt;country&amp;gt; sale) + stdev(total &amp;lt;country&amp;gt; sale)), country,sale))&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 14:20:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/need-help-on-a-nested-aggregation/m-p/675536#M245259</guid>
      <dc:creator>Gysbert_Wassenaar</dc:creator>
      <dc:date>2014-06-13T14:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: need help on a nested aggregation</title>
      <link>https://community.qlik.com/t5/QlikView/need-help-on-a-nested-aggregation/m-p/675537#M245260</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;that's correct !!&lt;/P&gt;&lt;P&gt;if you have time, could you give a quick explanation for the formula, it's still not cristal clear to me &lt;/P&gt;&lt;P&gt;also, how to use the dimension group instead of &amp;lt;country&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks !&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 15:59:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/need-help-on-a-nested-aggregation/m-p/675537#M245260</guid>
      <dc:creator />
      <dc:date>2014-06-13T15:59:34Z</dc:date>
    </item>
    <item>
      <title>Re: need help on a nested aggregation</title>
      <link>https://community.qlik.com/t5/QlikView/need-help-on-a-nested-aggregation/m-p/675538#M245261</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The rangemin function should compare the sales values at the lowest aggregation level, i.e. country,sale. That's why the the outer avg is aggregating over the dimensions sale and country: avg(aggr(something),country,sale)). The rangemin should compare the lowest level sale with the avg and stdev of sale at the country level. That's why those get the &lt;EM&gt;total &amp;lt;country&amp;gt; &lt;/EM&gt;modifier&lt;EM&gt;.&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jun 2014 16:16:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/need-help-on-a-nested-aggregation/m-p/675538#M245261</guid>
      <dc:creator>Gysbert_Wassenaar</dc:creator>
      <dc:date>2014-06-13T16:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: need help on a nested aggregation</title>
      <link>https://community.qlik.com/t5/QlikView/need-help-on-a-nested-aggregation/m-p/675539#M245262</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;actually after adding a new dimension "product" and doing more tests, I had some discrepencies and I finally found out the the aggr () had to be nested inside the rangemin() : &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;avg(rangemin(sale, aggr(avg(total &amp;lt;country&amp;gt; sale) &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; + stdev(total &amp;lt;country&amp;gt; sale), country, sale)))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;since my dimension is in a group, the final formula is : &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;avg(rangemin(sale, aggr(avg(total &amp;lt;$(=getcurrentfield("group1"))&amp;gt; sale) &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; + stdev(total &amp;lt;$(=getcurrentfield("group1"))&amp;gt; sale), $(=getcurrentfield("group1")), sale)))&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Jun 2014 12:56:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/need-help-on-a-nested-aggregation/m-p/675539#M245262</guid>
      <dc:creator />
      <dc:date>2014-06-17T12:56:37Z</dc:date>
    </item>
  </channel>
</rss>

