<?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 pivot table calculation - avg vertically and agg horizontally in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/pivot-table-calculation-avg-vertically-and-agg-horizontally/m-p/1832032#M68637</link>
    <description>&lt;P&gt;Hi Qlik community,&lt;/P&gt;&lt;P&gt;Would like to get help from the community on one of my use case. There is a requirement for a pivot table, whereby to calculate measure (sales) with apply average calculation vertically, while aggregate calculation horizontally.&lt;/P&gt;&lt;P&gt;I'm not sure whether this use case is possible? If possible can please shed on light on this ?&lt;/P&gt;&lt;P&gt;To illustrate, I attached a sample qvf.&amp;nbsp; For e.g. custA:&lt;/P&gt;&lt;P&gt;I would need the calculated figure for year (highlighted) to be the Average of the sales, i.e.&amp;nbsp;&lt;/P&gt;&lt;P&gt;year 2020: (78 + 95 + 46 + 75) /4 = 73.5 (currently is 294, not what I need)&lt;/P&gt;&lt;P&gt;year 2021: (15 + 95)/2 = 55&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="custA.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/60931i59C564AA32230625/image-size/medium?v=v2&amp;amp;px=400" role="button" title="custA.png" alt="custA.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Same behaviors should apply if the pivot table is collapse.&lt;/P&gt;&lt;P&gt;Below is the calculation formula I had tried:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SUM(AGGR( nodistinct
Sum(sales),year, month, customer, product));

AVG(AGGR( nodistinct
Sum(sales),year, month, customer, product))&lt;/LI-CODE&gt;&lt;P&gt;But the problem here is whichever I used, it will end up applied either SUM or AVG for the whole table. What I need is to calculate Average vertically, while SUM aggregate horizontally.&lt;/P&gt;&lt;P&gt;Appreciate any input. Thanks.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Kenny.&lt;/P&gt;</description>
    <pubDate>Mon, 30 Aug 2021 04:00:40 GMT</pubDate>
    <dc:creator>KennyTan</dc:creator>
    <dc:date>2021-08-30T04:00:40Z</dc:date>
    <item>
      <title>pivot table calculation - avg vertically and agg horizontally</title>
      <link>https://community.qlik.com/t5/App-Development/pivot-table-calculation-avg-vertically-and-agg-horizontally/m-p/1832032#M68637</link>
      <description>&lt;P&gt;Hi Qlik community,&lt;/P&gt;&lt;P&gt;Would like to get help from the community on one of my use case. There is a requirement for a pivot table, whereby to calculate measure (sales) with apply average calculation vertically, while aggregate calculation horizontally.&lt;/P&gt;&lt;P&gt;I'm not sure whether this use case is possible? If possible can please shed on light on this ?&lt;/P&gt;&lt;P&gt;To illustrate, I attached a sample qvf.&amp;nbsp; For e.g. custA:&lt;/P&gt;&lt;P&gt;I would need the calculated figure for year (highlighted) to be the Average of the sales, i.e.&amp;nbsp;&lt;/P&gt;&lt;P&gt;year 2020: (78 + 95 + 46 + 75) /4 = 73.5 (currently is 294, not what I need)&lt;/P&gt;&lt;P&gt;year 2021: (15 + 95)/2 = 55&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="custA.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/60931i59C564AA32230625/image-size/medium?v=v2&amp;amp;px=400" role="button" title="custA.png" alt="custA.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Same behaviors should apply if the pivot table is collapse.&lt;/P&gt;&lt;P&gt;Below is the calculation formula I had tried:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SUM(AGGR( nodistinct
Sum(sales),year, month, customer, product));

AVG(AGGR( nodistinct
Sum(sales),year, month, customer, product))&lt;/LI-CODE&gt;&lt;P&gt;But the problem here is whichever I used, it will end up applied either SUM or AVG for the whole table. What I need is to calculate Average vertically, while SUM aggregate horizontally.&lt;/P&gt;&lt;P&gt;Appreciate any input. Thanks.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Kenny.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Aug 2021 04:00:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/pivot-table-calculation-avg-vertically-and-agg-horizontally/m-p/1832032#M68637</guid>
      <dc:creator>KennyTan</dc:creator>
      <dc:date>2021-08-30T04:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: pivot table calculation - avg vertically and agg horizontally</title>
      <link>https://community.qlik.com/t5/App-Development/pivot-table-calculation-avg-vertically-and-agg-horizontally/m-p/1832037#M68640</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try like below&lt;/P&gt;&lt;P&gt;If(Dimensionality()=1,&lt;BR /&gt;AVG(sales),&lt;/P&gt;&lt;P&gt;SUM(sales))&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MayilVahanan_0-1630297323381.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/60932iA79B45D8BB14D7A0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MayilVahanan_0-1630297323381.png" alt="MayilVahanan_0-1630297323381.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Aug 2021 04:22:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/pivot-table-calculation-avg-vertically-and-agg-horizontally/m-p/1832037#M68640</guid>
      <dc:creator>MayilVahanan</dc:creator>
      <dc:date>2021-08-30T04:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: pivot table calculation - avg vertically and agg horizontally</title>
      <link>https://community.qlik.com/t5/App-Development/pivot-table-calculation-avg-vertically-and-agg-horizontally/m-p/1832072#M68648</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/17935"&gt;@MayilVahanan&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thanks for the input, this work well for calculation when break down by product, but calculated figure seem not correct when it aggregate, for e.g. for custA below:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="custA.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/60940i1B41903A57B19A9F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="custA.png" alt="custA.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I expect to have the year calculation (highlighted) = (111 + 116 + 46 + 107)/4 = 95, but it calculate as 54.286 (not sure how this figure come from).&lt;/P&gt;&lt;P&gt;Is it possible&amp;nbsp; to have similar behavior even when the pivot table is group together?&lt;/P&gt;&lt;P&gt;Thanks and Regards,&lt;/P&gt;&lt;P&gt;Kenny.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Aug 2021 08:04:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/pivot-table-calculation-avg-vertically-and-agg-horizontally/m-p/1832072#M68648</guid>
      <dc:creator>KennyTan</dc:creator>
      <dc:date>2021-08-30T08:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: pivot table calculation - avg vertically and agg horizontally</title>
      <link>https://community.qlik.com/t5/App-Development/pivot-table-calculation-avg-vertically-and-agg-horizontally/m-p/1832091#M68650</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Try like below&lt;/P&gt;&lt;P&gt;If(Dimensionality()=1,&lt;BR /&gt;Sum(sales)/Count(Distinct month),&lt;/P&gt;&lt;P&gt;SUM(sales))&lt;/P&gt;&lt;P&gt;It based on ur requirement.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Aug 2021 09:03:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/pivot-table-calculation-avg-vertically-and-agg-horizontally/m-p/1832091#M68650</guid>
      <dc:creator>MayilVahanan</dc:creator>
      <dc:date>2021-08-30T09:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: pivot table calculation - avg vertically and agg horizontally</title>
      <link>https://community.qlik.com/t5/App-Development/pivot-table-calculation-avg-vertically-and-agg-horizontally/m-p/1832208#M68670</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://community.qlik.com/t5/user/viewprofilepage/user-id/17935" target="_blank"&gt;@MayilVahanan&lt;/A&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thanks, i didn't aware the level of dimension have impact on the calculation with using Dimensionality(), so didn't provide an accurate scenario to reflect my use case, but it was close.&lt;/P&gt;&lt;P&gt;What if i have 3 level of dimension? year, month and week. I tried below code using example provided by you, but the total average calculated year's figure seem a bit off (see highlighted):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="custA1.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/60965iF17BDE5A1B2B963E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="custA1.png" alt="custA1.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="custA2.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/60967i149B5F3C2AE05EB8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="custA2.png" alt="custA2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;formula i had tried:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;If( Dimensionality()=2, Sum(sales)/Count(Distinct week),
	If(Dimensionality()=1,Sum(sales)/Count(Distinct month),SUM(sales)))&lt;/LI-CODE&gt;&lt;P&gt;Can you please help identify which section i getting it wrong? I would like to have the same behaviour, but with additional new "week" dimension as row.&lt;/P&gt;&lt;P&gt;I re-attached new set of qvf data just in case.&lt;/P&gt;&lt;P&gt;Thanks for your kind reply and time.&lt;/P&gt;&lt;P&gt;Kenny Tan.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Aug 2021 14:42:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/pivot-table-calculation-avg-vertically-and-agg-horizontally/m-p/1832208#M68670</guid>
      <dc:creator>KennyTan</dc:creator>
      <dc:date>2021-08-30T14:42:55Z</dc:date>
    </item>
    <item>
      <title>Re: pivot table calculation - avg vertically and agg horizontally</title>
      <link>https://community.qlik.com/t5/App-Development/pivot-table-calculation-avg-vertically-and-agg-horizontally/m-p/1832365#M68683</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Its looks correct only.&amp;nbsp;&lt;/P&gt;&lt;P&gt;what is the expected o/p for ur latest file?&lt;/P&gt;&lt;P&gt;Year total: =Sum(Sales)/ no of distinct month , so total is 99 which is correct.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 02:41:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/pivot-table-calculation-avg-vertically-and-agg-horizontally/m-p/1832365#M68683</guid>
      <dc:creator>MayilVahanan</dc:creator>
      <dc:date>2021-08-31T02:41:41Z</dc:date>
    </item>
  </channel>
</rss>

