<?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: if-statement expression not aggregating correctly in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409325#M490747</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks rebeccad - I think this works with the example data because of the small number of records. When the data scales up to millions of rows this solution does not work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think I need to put the aggregation outside the if statement (or use a set expression instead), but I can get it to work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="23412" class="jive-image-thumbnail jive-image" height="207" onclick="" alt="test 1.png" src="/legacyfs/online/23412_test 1.png" width="736" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 12 Oct 2012 15:25:27 GMT</pubDate>
    <dc:creator>rothtd</dc:creator>
    <dc:date>2012-10-12T15:25:27Z</dc:date>
    <item>
      <title>if-statement expression not aggregating correctly</title>
      <link>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409321#M490743</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P _mce_style="margin-bottom: .0001pt;" style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN _mce_style="font-family: 'Arial','sans-serif';" style="font-family: 'Arial','sans-serif';"&gt;Can someone help me with a percentage calculation that is not aggregating correctly? My expressions are using if-statements to filter out rows in a chart accordingly. [DPC %] is calculating correctly for each individual line in the chart, but the total for the expression is wrong. The total for [DPC %] is including rows in the chart are filtered out, so it is ignoring the if-statement. I believe this is because my expressions use sum(x) inside the if-statement – but I don’t know how else to do this expression. Any ideas?&lt;/SPAN&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P _mce_style="margin-bottom: .0001pt;" style="margin-bottom: 0.0001pt;"&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P _mce_style="margin-bottom: .0001pt;" style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN _mce_style="font-family: 'Arial','sans-serif';" style="font-family: 'Arial','sans-serif';"&gt;&lt;IMG __jive_id="23402" _mce_src="http://community.qlik.com/servlet/JiveServlet/downloadImage/23402/right.png" class="jive-image-thumbnail jive-image" height="267" onclick="" alt="right.png" src="https://community.qlik.com/legacyfs/online/23402_right.png" width="836" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P _mce_style="margin-bottom: .0001pt;" style="margin-bottom: 0.0001pt;"&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P _mce_style="margin-bottom: .0001pt;" style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN _mce_style="font-family: 'Arial','sans-serif';" style="font-family: 'Arial','sans-serif';"&gt;&lt;IMG __jive_id="23403" _mce_src="http://community.qlik.com/servlet/JiveServlet/downloadImage/23403/wrong.png" class="jive-image-thumbnail jive-image" height="224" onclick="" alt="wrong.png" src="https://community.qlik.com/legacyfs/online/23403_wrong.png" width="822" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P _mce_style="margin-bottom: .0001pt;" style="margin-bottom: 0.0001pt;"&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P _mce_style="margin-bottom: .0001pt;" style="margin-bottom: 0.0001pt;"&gt;Expressions:&lt;/P&gt;&lt;P _mce_style="margin-bottom: .0001pt;" style="margin-bottom: 0.0001pt;"&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P _mce_style="margin-bottom: .0001pt;" style="margin-bottom: 0.0001pt;"&gt;Net Sales:&lt;/P&gt;&lt;P _mce_style="margin-bottom: .0001pt;" style="margin-bottom: 0.0001pt;"&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;=if(vSalesFilter_UseTheFilterFlag='Yes',&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if(sum([Net Sales]) &amp;gt;= vSalesFilter, sum([Net Sales])),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;sum([Net Sales]))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;DPC $&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;=if(vSalesFilter_UseTheFilterFlag='Yes',&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if(sum([Net Sales]) &amp;gt;= vSalesFilter, sum([DPC])),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;sum([DPC]))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;DPC %&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;=&lt;/P&gt;&lt;P&gt;if(vSalesFilter_UseTheFilterFlag='Yes',&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if(sum([Net Sales]) &amp;gt;= vSalesFilter, sum([DPC])),&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;sum([DPC]))&lt;/P&gt;&lt;P&gt;/&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;if(vSalesFilter_UseTheFilterFlag='Yes',&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if(sum([Net Sales]) &amp;gt;= vSalesFilter, sum([Net Sales])),&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;sum([Net Sales]))&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P _mce_style="margin-bottom: .0001pt;" style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN _mce_style="font-family: 'Arial','sans-serif';" style="font-family: 'Arial','sans-serif';"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Oct 2012 13:53:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409321#M490743</guid>
      <dc:creator>rothtd</dc:creator>
      <dc:date>2012-10-12T13:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: if-statement expression not aggregating correctly</title>
      <link>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409322#M490744</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Oct 2012 14:16:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409322#M490744</guid>
      <dc:creator />
      <dc:date>2012-10-12T14:16:43Z</dc:date>
    </item>
    <item>
      <title>Re: if-statement expression not aggregating correctly</title>
      <link>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409323#M490745</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Using set analysis, it shouldn't matter how many records you have. What part is not working? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Oct 2012 15:11:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409323#M490745</guid>
      <dc:creator />
      <dc:date>2012-10-12T15:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: if-statement expression not aggregating correctly</title>
      <link>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409324#M490746</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you think through how the expression total is evaluated, it first looks at the if-statement/s (which are true) then evaluates the sum(x) portion. At this point it would be a sum of all records, meaning the if-statement is negated. Thus, the rest of the chart works great - but the expression total is always a sum of all records regardless. This is why I think I need to embed the if logic within the sum statement, but I can quite figure out the best way of doing that.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Oct 2012 15:22:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409324#M490746</guid>
      <dc:creator>rothtd</dc:creator>
      <dc:date>2012-10-12T15:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: if-statement expression not aggregating correctly</title>
      <link>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409325#M490747</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks rebeccad - I think this works with the example data because of the small number of records. When the data scales up to millions of rows this solution does not work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think I need to put the aggregation outside the if statement (or use a set expression instead), but I can get it to work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="23412" class="jive-image-thumbnail jive-image" height="207" onclick="" alt="test 1.png" src="/legacyfs/online/23412_test 1.png" width="736" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Oct 2012 15:25:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409325#M490747</guid>
      <dc:creator>rothtd</dc:creator>
      <dc:date>2012-10-12T15:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: if-statement expression not aggregating correctly</title>
      <link>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409326#M490748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That was why I renamed your Net Sales column to Net Sales&amp;nbsp; (added one extra space) and then used your column headers as the expression:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[DPC $]/[Net Sales ] &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This way it will only evaluate based on the sums in the two columns.&amp;nbsp; Did you try that? Sorry, I guess I should have made that more clear. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Oct 2012 15:31:08 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409326#M490748</guid>
      <dc:creator />
      <dc:date>2012-10-12T15:31:08Z</dc:date>
    </item>
    <item>
      <title>Re: if-statement expression not aggregating correctly</title>
      <link>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409327#M490749</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That's a really good idea. I couldn't get it to work however. It is still calculating based on all rows vs. only the visible rows. I added a 2 on the column names instead of your space to make the rename more visible.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DPC% 2 expression:&lt;/P&gt;&lt;P&gt;=[DPC $2] / [Net Sales 2]&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="23417" class="jive-image-thumbnail jive-image" height="174" onclick="" alt="test 2.png" src="/legacyfs/online/23417_test 2.png" width="676" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Oct 2012 16:32:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409327#M490749</guid>
      <dc:creator>rothtd</dc:creator>
      <dc:date>2012-10-12T16:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: if-statement expression not aggregating correctly</title>
      <link>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409328#M490750</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you upload a sample file with customer data scrambled out? I tried a test document with a ton of records and it was working.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Oct 2012 16:43:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409328#M490750</guid>
      <dc:creator />
      <dc:date>2012-10-12T16:43:57Z</dc:date>
    </item>
    <item>
      <title>Re: if-statement expression not aggregating correctly</title>
      <link>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409329#M490751</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You'll notice on this version that when the filter is turned off it works fine, but when the filter is turned on it does not work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Filter off:&lt;/P&gt;&lt;P&gt; the DPC%2 total should be 33% (1,135,207,375 / 3,462,945,698 = 0.3278)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Filter on:&lt;/P&gt;&lt;P&gt;the DPC%2 total should be 26% (282,682,342 / 1,077,512,423 = 0.262)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Oct 2012 17:30:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409329#M490751</guid>
      <dc:creator>rothtd</dc:creator>
      <dc:date>2012-10-12T17:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: if-statement expression not aggregating correctly</title>
      <link>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409330#M490752</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;See if this works.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Oct 2012 18:07:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409330#M490752</guid>
      <dc:creator />
      <dc:date>2012-10-12T18:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: if-statement expression not aggregating correctly</title>
      <link>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409331#M490753</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That works! Thanks - that was exactly what I was looking for!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Oct 2012 18:20:45 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/if-statement-expression-not-aggregating-correctly/m-p/409331#M490753</guid>
      <dc:creator>rothtd</dc:creator>
      <dc:date>2012-10-12T18:20:45Z</dc:date>
    </item>
  </channel>
</rss>

