<?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: Sum formula is not working correctly in pivot table in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830583#M68447</link>
    <description>&lt;P&gt;I will make a sample version of the app and post it later today.&amp;nbsp; Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 23 Aug 2021 15:37:53 GMT</pubDate>
    <dc:creator>mikegrattan</dc:creator>
    <dc:date>2021-08-23T15:37:53Z</dc:date>
    <item>
      <title>Sum formula is not working correctly in pivot table</title>
      <link>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830285#M68425</link>
      <description>&lt;P&gt;I have the following formula for Adjusted Yield in my pivot table:&lt;/P&gt;&lt;P&gt;If(Sum(WalkbyQty) &amp;gt; 0, (Sum(EU_RecQty) / Sum(Acres)) + (Sum(WalkbyQty) / Sum(Acres)),(Sum(EU_RecQty) / Sum(Acres)))&lt;/P&gt;&lt;P&gt;In my rows, I have five dimensions for drill down.&amp;nbsp; The Adjusted Yield formula does not calculate correctly at the top two levels; however, if I drill down further, then the formula appears to work correctly.&amp;nbsp; I have a feeling this formula might require more refinement such as with the Aggr function, but I would like to get some feedback and suggestions please.&amp;nbsp; Thank you.&lt;/P&gt;&lt;P&gt;Example of incorrect calculation for Adj Yield:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mikegrattan_0-1629494552685.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/60540iC873AB929A5B2FD5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mikegrattan_0-1629494552685.png" alt="mikegrattan_0-1629494552685.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Drill down one level on G&amp;amp;H Farms and all numbers suddenly are calculated correctly:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mikegrattan_1-1629494600086.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/60541i417E7854749606FF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mikegrattan_1-1629494600086.png" alt="mikegrattan_1-1629494600086.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 21:24:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830285#M68425</guid>
      <dc:creator>mikegrattan</dc:creator>
      <dc:date>2021-08-20T21:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: Sum formula is not working correctly in pivot table</title>
      <link>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830291#M68426</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/49220"&gt;@mikegrattan&lt;/a&gt;&amp;nbsp; one way is to use dimensionality to aggregate your measure at each level of dimensions using aggr.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;=Pick(dimensionality(),
sum(aggr(If(Sum(WalkbyQty) &amp;gt; 0, (Sum(EU_RecQty) / Sum(Acres)) + (Sum(WalkbyQty) / Sum(Acres)),(Sum(EU_RecQty) / Sum(Acres))), Location)),

sum(aggr(If(Sum(WalkbyQty) &amp;gt; 0, (Sum(EU_RecQty) / Sum(Acres)) + (Sum(WalkbyQty) / Sum(Acres)),(Sum(EU_RecQty) / Sum(Acres))), Location, Grower)),

sum(aggr(If(Sum(WalkbyQty) &amp;gt; 0, (Sum(EU_RecQty) / Sum(Acres)) + (Sum(WalkbyQty) / Sum(Acres)),(Sum(EU_RecQty) / Sum(Acres))), Location, Grower, RanchName)),

sum(aggr(If(Sum(WalkbyQty) &amp;gt; 0, (Sum(EU_RecQty) / Sum(Acres)) + (Sum(WalkbyQty) / Sum(Acres)),(Sum(EU_RecQty) / Sum(Acres))), Location, Grower, RanchName, Commodity)),

sum(aggr(If(Sum(WalkbyQty) &amp;gt; 0, (Sum(EU_RecQty) / Sum(Acres)) + (Sum(WalkbyQty) / Sum(Acres)),(Sum(EU_RecQty) / Sum(Acres))), Location, Grower, RanchName, Commodity, WorkOrder)))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 15:21:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830291#M68426</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2021-08-23T15:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Sum formula is not working correctly in pivot table</title>
      <link>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830571#M68441</link>
      <description>&lt;P&gt;Hello Kushal,&lt;/P&gt;&lt;P&gt;I'm still seeing strange behavior after using your formula (adjusted to add a comma after "dimensionality()").&amp;nbsp; I'm only getting the right numbers after drilling down to level 3 in the Rows section.&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;Thank you for your time.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 15:09:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830571#M68441</guid>
      <dc:creator>mikegrattan</dc:creator>
      <dc:date>2021-08-23T15:09:10Z</dc:date>
    </item>
    <item>
      <title>Re: Sum formula is not working correctly in pivot table</title>
      <link>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830576#M68443</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/49220"&gt;@mikegrattan&lt;/a&gt;&amp;nbsp; make sure that you are using actual field name in Aggr function. For eg. I have written &lt;STRONG&gt;Location&lt;/STRONG&gt;, but in your case field name might be LOCATION_NAME. It will be hard to tell what's going wrong without looking into your data.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 15:23:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830576#M68443</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2021-08-23T15:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: Sum formula is not working correctly in pivot table</title>
      <link>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830580#M68445</link>
      <description>&lt;P&gt;There was one field name that had to be changed; Commodity should be CommDesc (Commodity is a valid field name, but CommDesc is being used in the pivot table).&amp;nbsp; I have changed the formula to use CommDesc, but there is still an aggregation issue at level one (Location) and level two (Grower).&amp;nbsp; After I drill down so level 3 (Ranch) is showing, the numbers are good.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 15:33:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830580#M68445</guid>
      <dc:creator>mikegrattan</dc:creator>
      <dc:date>2021-08-23T15:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: Sum formula is not working correctly in pivot table</title>
      <link>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830581#M68446</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/49220"&gt;@mikegrattan&lt;/a&gt;&amp;nbsp; would you be able to share sample app? with expected output at level 1 and 2?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 15:34:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830581#M68446</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2021-08-23T15:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: Sum formula is not working correctly in pivot table</title>
      <link>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830583#M68447</link>
      <description>&lt;P&gt;I will make a sample version of the app and post it later today.&amp;nbsp; Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 15:37:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830583#M68447</guid>
      <dc:creator>mikegrattan</dc:creator>
      <dc:date>2021-08-23T15:37:53Z</dc:date>
    </item>
    <item>
      <title>Re: Sum formula is not working correctly in pivot table</title>
      <link>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830597#M68448</link>
      <description>&lt;P&gt;Here's a sample copy of the application. I've reduced the amount of data and removed all unnecessary sheets and charts; only the pivot table is included, and I've modified it so only the fields involved in the formula are in the table.&amp;nbsp; With those modifications, it appears the formula you suggested is showing correct numbers after you drill down to level two. I'm not sure why it behaves this way, so any insight you can provide will be very appreciated.&amp;nbsp; Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Sep 2021 14:24:48 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830597#M68448</guid>
      <dc:creator>mikegrattan</dc:creator>
      <dc:date>2021-09-14T14:24:48Z</dc:date>
    </item>
    <item>
      <title>Re: Sum formula is not working correctly in pivot table</title>
      <link>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830638#M68452</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/49220"&gt;@mikegrattan&lt;/a&gt;&amp;nbsp; in your sample what should be the value at level 1? Could you give one example?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 21:12:49 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830638#M68452</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2021-08-23T21:12:49Z</dc:date>
    </item>
    <item>
      <title>Re: Sum formula is not working correctly in pivot table</title>
      <link>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830642#M68453</link>
      <description>&lt;P&gt;If you filter on Year = 2021, CropType = LTC, and Location = SAL, the Adj Yield value at level one (SAL) shows up as 689.&amp;nbsp; If you drill down to level 3 to show Ranches under a Grower, the value at level one changes to 1064 which is the correct number. Note that the Adj Yield column is my original formula and the Adjusted Yield column is your suggested formula.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Aug 2021 21:23:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1830642#M68453</guid>
      <dc:creator>mikegrattan</dc:creator>
      <dc:date>2021-08-23T21:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: Sum formula is not working correctly in pivot table</title>
      <link>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1832672#M68725</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/336"&gt;@Kushal_Chawda&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;I haven't been able to modify your formula to work correctly at all levels.&amp;nbsp; Is there another approach I should consider?&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 20:57:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1832672#M68725</guid>
      <dc:creator>mikegrattan</dc:creator>
      <dc:date>2021-08-31T20:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: Sum formula is not working correctly in pivot table</title>
      <link>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1832697#M68728</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/49220"&gt;@mikegrattan&lt;/a&gt;&amp;nbsp; Your data model looks complex and this is the reason why you are facing this issue. Issue is that you have null values for Commodity dimensions, so when you drill down to to lower level pivot does not show null values and calculates correctly. At higher level, sum function always sums entire set of values. To avoid this one workaround is below.&lt;/P&gt;&lt;P&gt;If(Sum({&amp;lt;Commodity={"*"}&amp;gt;}WalkbyQty) &amp;gt; 0, (Sum({&amp;lt;Commodity={"*"}&amp;gt;}EU_RecQty) / Sum({&amp;lt;Commodity={"*"}&amp;gt;}Acres)) +&lt;BR /&gt;(Sum({&amp;lt;Commodity={"*"}&amp;gt;}WalkbyQty) / Sum({&amp;lt;Commodity={"*"}&amp;gt;}Acres)),&lt;BR /&gt;(Sum({&amp;lt;Commodity={"*"}&amp;gt;}EU_RecQty) / Sum({&amp;lt;Commodity={"*"}&amp;gt;}Acres)))&lt;/P&gt;&lt;P&gt;I am not sure if this completely solve the issue, but if at other level null values comes up and you don't want to consider that then you may also need to include the condition for that dimension like eg.&lt;/P&gt;&lt;P&gt;Sum({&amp;lt;Commodity={'*'}, Rower={'*'}&amp;gt;}Acres)&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 23:54:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1832697#M68728</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2021-08-31T23:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: Sum formula is not working correctly in pivot table</title>
      <link>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1832937#M68753</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/336"&gt;@Kushal_Chawda&lt;/a&gt;&amp;nbsp;Yes, that helps to explain what's going on.&amp;nbsp; Some of the data being loaded doesn't include Commodity, so that could leave null values in certain analyses.&amp;nbsp; I will try your suggestions.&amp;nbsp; Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 14:21:16 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Sum-formula-is-not-working-correctly-in-pivot-table/m-p/1832937#M68753</guid>
      <dc:creator>mikegrattan</dc:creator>
      <dc:date>2021-09-01T14:21:16Z</dc:date>
    </item>
  </channel>
</rss>

