<?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 nested aggregation to calculate weighted average in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/nested-aggregation-to-calculate-weighted-average/m-p/644275#M476651</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Suppose I have a table of values like this:&lt;/P&gt;&lt;P&gt;year&amp;nbsp; value&lt;/P&gt;&lt;P&gt;2011 1&lt;/P&gt;&lt;P&gt;2011 0&lt;/P&gt;&lt;P&gt;2011 0&lt;/P&gt;&lt;P&gt;2011 1&lt;/P&gt;&lt;P&gt;2012 0&lt;/P&gt;&lt;P&gt;2012 1&lt;/P&gt;&lt;P&gt;2013 0&lt;/P&gt;&lt;P&gt;2013 0&lt;/P&gt;&lt;P&gt;2013 1&lt;/P&gt;&lt;P&gt;2013 1&lt;/P&gt;&lt;P&gt;2013 1&lt;/P&gt;&lt;P&gt;That is, 4 values for 2011, 2 values for 2012, and 5 values for 2013.&lt;/P&gt;&lt;P&gt;I would like to implement the weighted average: (2011*4 + 2012*2 + 2013*5 ) / (4+2+5).&amp;nbsp; Or in the general case, that would be weighted average = sum( Ni * Xi /sum(Ni)) where i is in {2011, 2012, 2013} in this example.&amp;nbsp; I think it is a nested aggregate that I want, and I don't know if it is possible or how best to implement it (I'm a newbie).&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want the end user to select years 2011 and 2012 (say) from displayed list, and the weighted average to be calculated for data corresponding to just those 2 years (i in {2011, 2012} only).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was trying something like this: $(=sum(count(value)*year / $(=sum(count(value)) ) )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions would be appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 22 May 2014 20:44:17 GMT</pubDate>
    <dc:creator />
    <dc:date>2014-05-22T20:44:17Z</dc:date>
    <item>
      <title>nested aggregation to calculate weighted average</title>
      <link>https://community.qlik.com/t5/QlikView/nested-aggregation-to-calculate-weighted-average/m-p/644275#M476651</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Suppose I have a table of values like this:&lt;/P&gt;&lt;P&gt;year&amp;nbsp; value&lt;/P&gt;&lt;P&gt;2011 1&lt;/P&gt;&lt;P&gt;2011 0&lt;/P&gt;&lt;P&gt;2011 0&lt;/P&gt;&lt;P&gt;2011 1&lt;/P&gt;&lt;P&gt;2012 0&lt;/P&gt;&lt;P&gt;2012 1&lt;/P&gt;&lt;P&gt;2013 0&lt;/P&gt;&lt;P&gt;2013 0&lt;/P&gt;&lt;P&gt;2013 1&lt;/P&gt;&lt;P&gt;2013 1&lt;/P&gt;&lt;P&gt;2013 1&lt;/P&gt;&lt;P&gt;That is, 4 values for 2011, 2 values for 2012, and 5 values for 2013.&lt;/P&gt;&lt;P&gt;I would like to implement the weighted average: (2011*4 + 2012*2 + 2013*5 ) / (4+2+5).&amp;nbsp; Or in the general case, that would be weighted average = sum( Ni * Xi /sum(Ni)) where i is in {2011, 2012, 2013} in this example.&amp;nbsp; I think it is a nested aggregate that I want, and I don't know if it is possible or how best to implement it (I'm a newbie).&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want the end user to select years 2011 and 2012 (say) from displayed list, and the weighted average to be calculated for data corresponding to just those 2 years (i in {2011, 2012} only).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was trying something like this: $(=sum(count(value)*year / $(=sum(count(value)) ) )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions would be appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 May 2014 20:44:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/nested-aggregation-to-calculate-weighted-average/m-p/644275#M476651</guid>
      <dc:creator />
      <dc:date>2014-05-22T20:44:17Z</dc:date>
    </item>
    <item>
      <title>Re: nested aggregation to calculate weighted average</title>
      <link>https://community.qlik.com/t5/QlikView/nested-aggregation-to-calculate-weighted-average/m-p/644276#M476652</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi there , please find attachment&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 May 2014 21:26:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/nested-aggregation-to-calculate-weighted-average/m-p/644276#M476652</guid>
      <dc:creator>preminqlik</dc:creator>
      <dc:date>2014-05-22T21:26:04Z</dc:date>
    </item>
    <item>
      <title>Re: nested aggregation to calculate weighted average</title>
      <link>https://community.qlik.com/t5/QlikView/nested-aggregation-to-calculate-weighted-average/m-p/644277#M476653</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think I figured it out:&lt;/P&gt;&lt;P&gt;=(sum(year*aggr(count(value), year)))/count(value)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Finally realized that aggr is a lot like "GROUP BY" in SQL.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 23 May 2014 02:18:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/nested-aggregation-to-calculate-weighted-average/m-p/644277#M476653</guid>
      <dc:creator />
      <dc:date>2014-05-23T02:18:53Z</dc:date>
    </item>
  </channel>
</rss>

