<?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 if statement - different result in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/if-statement-different-result/m-p/197925#M57410</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks for your reply. "Nr" is in a seperate tabel with only two records - one with NR=1, and one with NR=2. The other fields are in one table.&lt;/P&gt;&lt;P&gt;But, your explanation seems right. This could also explain why the result sometimes was correct - and other times incorrect&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;Nils&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 23 Nov 2010 00:48:47 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2010-11-23T00:48:47Z</dc:date>
    <item>
      <title>if statement - different result</title>
      <link>https://community.qlik.com/t5/QlikView/if-statement-different-result/m-p/197923#M57408</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;These two statements should give the same result, but don't. I'm using a scatter-chart.&lt;/P&gt;&lt;P&gt;Can anyone explain why the two statements return different results? It works with the second version&lt;/P&gt;&lt;P&gt;1) if(Nr = 1, sum({$&amp;lt;Year={2008, 2009}&amp;gt;} AMOUNT_LOCAL), sum({$&amp;lt;Year={2008, 2009}&amp;gt;} AMOUNT_EURO)) / Sum({$&amp;lt;Year={2008, 2009}&amp;gt;} QUANTITY)&lt;/P&gt;&lt;P&gt;2) sum({$&amp;lt;Year={2008, 2009}&amp;gt;} if(Nr = 1, AMOUNT_LOCAL, AMOUNT_EURO)) / Sum({$&amp;lt;Year={2008, 2009}&amp;gt;} QUANTITY)&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;Nils&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Nov 2010 00:23:42 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/if-statement-different-result/m-p/197923#M57408</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-11-23T00:23:42Z</dc:date>
    </item>
    <item>
      <title>if statement - different result</title>
      <link>https://community.qlik.com/t5/QlikView/if-statement-different-result/m-p/197924#M57409</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I assume your data looks something like this?&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;Year, Nr, AMOUNT_LOCAL, AMOUNT_EURO, QUANTITY&lt;BR /&gt;2008, 1, 2000, 5000, 200&lt;BR /&gt;2009, 0, 3000, 4000, 400&lt;/P&gt;&lt;P&gt;For this, you want (2000 + 4000) / (200 + 400) = 10?&lt;/P&gt;&lt;P&gt;The difference in your expressions is WHEN they evaluate Nr. The first evaluates it ONCE for the entire table. Since the table contains values of Nr that are not 1, the condition is false, so ALL rows will be in AMOUNT_EURO. That is not what you want.&lt;/P&gt;&lt;P&gt;The second expression evaluates NR on a row-by-row basis. So it will realize that the first row should take AMOUNT_LOCAL, and the second row should take AMOUNT_EURO.&lt;/P&gt;&lt;P&gt;Untested, but I am guessing that the following is a more efficient way to get the same result. In this expression, set analysis splits your selected data into two groups, the first for Nr=1 and the second for all other values of Nr. It can then do a sum for each group individually without having to check the NR for every row.&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;(sum({&amp;lt;Year={'2008','2009'},Nr*={'1'}&amp;gt;} AMOUNT_LOCAL)&lt;BR /&gt;+sum({&amp;lt;Year={'2008','2009'},Nr-={'1'}&amp;gt;} AMOUNT_EURO))&lt;BR /&gt;/sum({&amp;lt;Year={'2008','2009'}&amp;gt;} QUANTITY)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Nov 2010 00:39:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/if-statement-different-result/m-p/197924#M57409</guid>
      <dc:creator>johnw</dc:creator>
      <dc:date>2010-11-23T00:39:29Z</dc:date>
    </item>
    <item>
      <title>if statement - different result</title>
      <link>https://community.qlik.com/t5/QlikView/if-statement-different-result/m-p/197925#M57410</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks for your reply. "Nr" is in a seperate tabel with only two records - one with NR=1, and one with NR=2. The other fields are in one table.&lt;/P&gt;&lt;P&gt;But, your explanation seems right. This could also explain why the result sometimes was correct - and other times incorrect&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;Nils&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 23 Nov 2010 00:48:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/if-statement-different-result/m-p/197925#M57410</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-11-23T00:48:47Z</dc:date>
    </item>
  </channel>
</rss>

