<?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 Nesting aggregations: SUM(AVG())? in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Nesting-aggregations-SUM-AVG/m-p/156116#M32101</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It looks like you need to use the Aggr() function. The Aggr() function returns an array of values based on a given criteria. so if you want to sum up by month, the aggr function will return an array of sums by month that can be aggregated again. Here is a nice short video made by the Qlik team on the aggr() function and how to use it. Hope it helps!&lt;/P&gt;&lt;P&gt;[View:http://community.qlik.com/cfs-file.ashx/__key/CommunityServer.Discussions.Components.Files/11/6758.Multi_2D00_pass-Aggregation.wmv:550:0]&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 23 Feb 2010 13:37:53 GMT</pubDate>
    <dc:creator>gardan</dc:creator>
    <dc:date>2010-02-23T13:37:53Z</dc:date>
    <item>
      <title>Nesting aggregations: SUM(AVG())?</title>
      <link>https://community.qlik.com/t5/QlikView/Nesting-aggregations-SUM-AVG/m-p/156115#M32100</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&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;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can't get my head around how to nest different types of aggregations. I basically need the SUM() of an AVG(). Once I figured out how to nest aggregations I'm sure I find a way to present the resulting data in different diagram types. Let me provide with you with some example data and some SQL describing what I want to do:&lt;/P&gt;&lt;P&gt;My warehouse dumps every day the quantity for each SKU in the warehouse. The Result looks something like below. The original has a few more interesting rows like monetary value per row etc. but you get an idea.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE ___default_attr="plain" class="jive_text_macro jive_macro_code" jivemacro="code"&gt;date | quantity | sku&lt;BR /&gt;------------+----------+----------&lt;BR /&gt; 2006-07-16 | 5316 | sku00&lt;BR /&gt; 2006-07-16 | 1875 | sku05&lt;BR /&gt; 2006-07-16 | 368 | sku10&lt;BR /&gt; 2006-07-16 | 917 | sku20&lt;BR /&gt; 2006-07-16 | 10928 | sku50&lt;BR /&gt; 2006-07-17 | 5316 | sku00&lt;BR /&gt; 2006-07-17 | 1875 | sku05&lt;BR /&gt; 2006-07-17 | 368 | sku10&lt;BR /&gt; 2006-07-17 | 917 | sku20&lt;BR /&gt; 2006-07-17 | 10928 | sku50&lt;BR /&gt; 2006-07-18 | 3487 | sku00&lt;BR /&gt; 2006-07-18 | 1871 | sku05&lt;BR /&gt; 2006-07-18 | 368 | sku10&lt;BR /&gt; 2006-07-18 | 914 | sku20&lt;BR /&gt; 2006-07-18 | 10753 | sku50&lt;BR /&gt; 2006-07-21 | 4211 | sku00&lt;BR /&gt; 2006-07-21 | 1871 | sku05&lt;BR /&gt; 2006-07-21 | 368 | sku10&lt;BR /&gt; 2006-07-21 | 906 | sku20&lt;BR /&gt; 2006-07-21 | 10694 | sku50&lt;BR /&gt; 2006-07-22 | 4211 | sku00&lt;BR /&gt; 2006-07-22 | 1859 | sku05&lt;BR /&gt; 2006-07-22 | 368 | sku10&lt;BR /&gt; 2006-07-22 | 908 | sku20&lt;BR /&gt; 2006-07-22 | 10694 | sku50&lt;BR /&gt; ...&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm fine with reading the SQL data into qlickview. I also can display it and use drill down groups for selecting by year, month, day and the like.&lt;/P&gt;&lt;P&gt;But to make sense of the data I want to know the average quantity for any SKU. In SQL land I would do something like this to get average quantity by month and sku:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE ___default_attr="plain" class="jive_text_macro jive_macro_code" jivemacro="code"&gt;SELECT date(date_trunc('month', date)) as month, avg(quantity), sku FROM footab GROUP BY sku, month;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE ___default_attr="plain" class="jive_text_macro jive_macro_code" jivemacro="code"&gt;month | avg | sku&lt;BR /&gt;------------+-------+----------&lt;BR /&gt; 2006-07-01 | 4266 | sku00&lt;BR /&gt; 2006-07-01 | 1859 | sku05&lt;BR /&gt; 2006-07-01 | 368 | sku10&lt;BR /&gt; 2006-07-01 | 905 | sku20&lt;BR /&gt; 2006-07-01 | 10738 | sku50&lt;BR /&gt; 2006-08-01 | 2745 | sku00&lt;BR /&gt; 2006-08-01 | 1608 | sku05&lt;BR /&gt; 2006-08-01 | 368 | sku10&lt;BR /&gt; 2006-08-01 | 1 | sku12&lt;BR /&gt; 2006-08-01 | 2 | sku13&lt;BR /&gt; 2006-08-01 | 797 | sku20&lt;BR /&gt; 2006-08-01 | 10568 | sku50&lt;BR /&gt; 2006-08-01 | 2 | sku90&lt;BR /&gt; 2006-09-01 | 420 | sku00&lt;BR /&gt; ...&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;P&gt;But in addition I want to know the TOTAL quantity per month. This would obyiously be more interesting for monetary value or storage volume. In SQL I would do this with a subquery:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE ___default_attr="plain" class="jive_text_macro jive_macro_code" jivemacro="code"&gt;SELECT month, sum(avg) FROM (&lt;BR /&gt; SELECT date(date_trunc('month', date)) as month, avg(quantity)::integer, sku FROM footab GROUP BY sku&lt;BR /&gt;) group by month;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE ___default_attr="plain" class="jive_text_macro jive_macro_code" jivemacro="code"&gt;month | sum&lt;BR /&gt;------------+-------&lt;BR /&gt; 2006-07-01 | 18136&lt;BR /&gt; 2006-08-01 | 19478&lt;BR /&gt; 2006-09-01 | 15860&lt;BR /&gt; ...&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;P&gt;So basically I do an SUM(AVG(quantty) GROUP BY sku, month) GROUP BY month. Works, but I'm loosing all interactive features of Qlikview. But I really do not understand how to do this nesting of aggrgations in QlikView itself. I have been reading the "NESTED AGGREGATIONS" chapter of the QlickView 8.5 handbook, but id didn't enlighten me. Any hints how to approach the "SUM(AVG(quantty) GROUP BY sku, month) GROUP BY month" issue in Qlikview itself and not in SQL?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;--md&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Feb 2010 13:18:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Nesting-aggregations-SUM-AVG/m-p/156115#M32100</guid>
      <dc:creator />
      <dc:date>2010-02-23T13:18:13Z</dc:date>
    </item>
    <item>
      <title>Nesting aggregations: SUM(AVG())?</title>
      <link>https://community.qlik.com/t5/QlikView/Nesting-aggregations-SUM-AVG/m-p/156116#M32101</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It looks like you need to use the Aggr() function. The Aggr() function returns an array of values based on a given criteria. so if you want to sum up by month, the aggr function will return an array of sums by month that can be aggregated again. Here is a nice short video made by the Qlik team on the aggr() function and how to use it. Hope it helps!&lt;/P&gt;&lt;P&gt;[View:http://community.qlik.com/cfs-file.ashx/__key/CommunityServer.Discussions.Components.Files/11/6758.Multi_2D00_pass-Aggregation.wmv:550:0]&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Feb 2010 13:37:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Nesting-aggregations-SUM-AVG/m-p/156116#M32101</guid>
      <dc:creator>gardan</dc:creator>
      <dc:date>2010-02-23T13:37:53Z</dc:date>
    </item>
    <item>
      <title>Nesting aggregations: SUM(AVG())?</title>
      <link>https://community.qlik.com/t5/QlikView/Nesting-aggregations-SUM-AVG/m-p/156117#M32102</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a lot, that solved it!&lt;/P&gt;&lt;P&gt;The basic code I needed was&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;sum(aggr(avg(quantity), sku))&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;I had problems with the embedded video, but downloading it from http://is.gd/908iE and playing it in VLS, worked.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;--md&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Feb 2010 14:35:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Nesting-aggregations-SUM-AVG/m-p/156117#M32102</guid>
      <dc:creator />
      <dc:date>2010-02-23T14:35:03Z</dc:date>
    </item>
    <item>
      <title>Nesting aggregations: SUM(AVG())?</title>
      <link>https://community.qlik.com/t5/QlikView/Nesting-aggregations-SUM-AVG/m-p/156118#M32103</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;both the links to the video doesn't work any more. I have got the same problem and want to know the solution too. Is the video still available somewhere?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 May 2011 11:43:16 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Nesting-aggregations-SUM-AVG/m-p/156118#M32103</guid>
      <dc:creator />
      <dc:date>2011-05-13T11:43:16Z</dc:date>
    </item>
    <item>
      <title>Nesting aggregations: SUM(AVG())?</title>
      <link>https://community.qlik.com/t5/QlikView/Nesting-aggregations-SUM-AVG/m-p/156119#M32104</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Open a new thread with your actual problem...&lt;/P&gt;&lt;P&gt;- Ralf&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 May 2011 11:48:48 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Nesting-aggregations-SUM-AVG/m-p/156119#M32104</guid>
      <dc:creator>rbecher</dc:creator>
      <dc:date>2011-05-13T11:48:48Z</dc:date>
    </item>
  </channel>
</rss>

