<?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 with IF statement inflates total in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Sum-with-IF-statement-inflates-total/m-p/926315#M527354</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK, i read through the Count Distinct info you linked, and that helps, I don't need to change the equation from Count distinct for efficiency's sake. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I have another field that does need to be summed (an amount) and I'm having the duplication issue.&amp;nbsp; Is there a workaround?&amp;nbsp; I can do SUM(AGGR(AVG(IF(APPL_RECD_DT &amp;gt; Campaign Start Dt, ANNL_AMT)),DOC_ID)) but that seems really resource heavy and i'm still not sure it gives the right result.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 18 Nov 2015 01:00:16 GMT</pubDate>
    <dc:creator />
    <dc:date>2015-11-18T01:00:16Z</dc:date>
    <item>
      <title>Sum with IF statement inflates total</title>
      <link>https://community.qlik.com/t5/QlikView/Sum-with-IF-statement-inflates-total/m-p/926312#M527351</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to use sum(FIELD_COUNTER) instead of COUNT(DISTINCT FIELD) for efficiency reasons, but when there is an IF statement within the SUM(), the result i get is greatly inflated.&amp;nbsp; I'm sure there's something I'm just missing or don't know about using IF with fields from 2 different tables, but maybe someone can help fill me in?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The attached doc shows the progression of expressions I've tried.&amp;nbsp; Count(DISTINCT APPL_NUM) and SUM(APPL_FG) are the same, as expected.&amp;nbsp; When I add the IF statement to the Count Distinct expression (In Yellow), it looks right, somewhat lower than the result before the IF statement.&amp;nbsp; But in the last field where I add the same IF statement to the SUM(APPL_FG) expression, the results are much higher than before.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I appreciate any guidance.&amp;nbsp; Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Nov 2015 21:18:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Sum-with-IF-statement-inflates-total/m-p/926312#M527351</guid>
      <dc:creator />
      <dc:date>2015-11-17T21:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: Sum with IF statement inflates total</title>
      <link>https://community.qlik.com/t5/QlikView/Sum-with-IF-statement-inflates-total/m-p/926313#M527352</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your sample file is a bit large for me at the moment, but in general, what you could be explained by the QV calculation engine:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.qlik.com/qlik-blogpost/3238"&gt;The Calculation Engine&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are using fields from different tables with an aggregation, QV needs to perform a JOINed temporary table on the fly. As you know, a JOIN may duplicate records, this may explain already the inflated Sum.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Besides this, maybe this is of interest:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.qlik.com/qlik-blogpost/3381"&gt;A Myth About Count(distinct …)&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Nov 2015 21:51:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Sum-with-IF-statement-inflates-total/m-p/926313#M527352</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2015-11-17T21:51:20Z</dc:date>
    </item>
    <item>
      <title>Re: Sum with IF statement inflates total</title>
      <link>https://community.qlik.com/t5/QlikView/Sum-with-IF-statement-inflates-total/m-p/926314#M527353</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry about that, I didn't realize the file i posted was so large.&amp;nbsp; Here's a more reasonable sized sample doc.&lt;/P&gt;&lt;P&gt;I see where those links you provided explain why I see inflated sums, but I'm still not sure how to resolve without going back to the less-efficient Count Distinct.&amp;nbsp; Can you help me with that?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Nov 2015 22:00:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Sum-with-IF-statement-inflates-total/m-p/926314#M527353</guid>
      <dc:creator />
      <dc:date>2015-11-17T22:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: Sum with IF statement inflates total</title>
      <link>https://community.qlik.com/t5/QlikView/Sum-with-IF-statement-inflates-total/m-p/926315#M527354</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK, i read through the Count Distinct info you linked, and that helps, I don't need to change the equation from Count distinct for efficiency's sake. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I have another field that does need to be summed (an amount) and I'm having the duplication issue.&amp;nbsp; Is there a workaround?&amp;nbsp; I can do SUM(AGGR(AVG(IF(APPL_RECD_DT &amp;gt; Campaign Start Dt, ANNL_AMT)),DOC_ID)) but that seems really resource heavy and i'm still not sure it gives the right result.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Nov 2015 01:00:16 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Sum-with-IF-statement-inflates-total/m-p/926315#M527354</guid>
      <dc:creator />
      <dc:date>2015-11-18T01:00:16Z</dc:date>
    </item>
  </channel>
</rss>

