<?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: COUNT(IF()) vs COUNT({&amp;lt;&amp;gt;}) in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/COUNT-IF-vs-COUNT-lt-gt/m-p/1651785#M48610</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Count({SetAnalysis})&lt;/STRONG&gt; = Override the current selection &lt;EM&gt;before&lt;/EM&gt; evaluating the Count expression. This filter action is applied to the whole data model, not row-by-row&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Count(IF())&lt;/STRONG&gt; = Evaluate the IF condition &lt;EM&gt;in each row,&amp;nbsp;&lt;/EM&gt;then apply the Count() function on top of the resulting dataset.&lt;/P&gt;&lt;P&gt;For example, let's say you have the following data model with 2 tables. Note that in &lt;EM&gt;Table 2&lt;/EM&gt; value (1,33) is duplicated.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="test.png" style="width: 274px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/24512i5B40B72E3D0B526C/image-size/large?v=v2&amp;amp;px=999" role="button" title="test.png" alt="test.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;1. Count({&amp;lt;event_type={33}&amp;gt;}od_id)&lt;/STRONG&gt;&lt;/EM&gt;&lt;STRONG&gt; = 2&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;First Qlik Sense makes a selection on &lt;EM&gt;event_type=33&lt;/EM&gt; (on top of current selection if any)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Then it performs a count on possible values of &lt;EM&gt;od_id&lt;/EM&gt;, which returns 2&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="test2.png" style="width: 276px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/24518i167AC83A6DB011A7/image-size/large?v=v2&amp;amp;px=999" role="button" title="test2.png" alt="test2.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;2.&amp;nbsp;Count(if(event_type=33, od_id) )&amp;nbsp; &lt;/STRONG&gt;&lt;/EM&gt;&lt;STRONG&gt;= 4&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;First Qlik Sense performs a natural join on tables containing &lt;EM&gt;event_type&lt;/EM&gt; and &lt;EM&gt;od_id.&amp;nbsp;&lt;/EM&gt;Because (1,33) is duplicated in &lt;EM&gt;Table 2,&amp;nbsp;&lt;/EM&gt;it is joined twice.&lt;/LI&gt;&lt;LI&gt;In this joined table, condition&amp;nbsp;&lt;SPAN&gt;&lt;EM&gt;if(event_type=33, od_id) &lt;/EM&gt;is evaluated for each row.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Finally, &lt;EM&gt;Count&lt;/EM&gt; is evaluated on results of the if condition&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;(including the null values) , which returns 4&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="test2.png" style="width: 461px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/24520i96A2742308EF0F5C/image-size/large?v=v2&amp;amp;px=999" role="button" title="test2.png" alt="test2.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;As a thumb rule, if condition should be used when evaluation needs to be done in a row-by-row basis. Otherwise it's better with Set Analysis.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Hope this helps!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;BR,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Vu Nguyen&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Nov 2019 09:43:57 GMT</pubDate>
    <dc:creator>vunguyenq89</dc:creator>
    <dc:date>2019-11-27T09:43:57Z</dc:date>
    <item>
      <title>COUNT(IF()) vs COUNT({&lt;&gt;})</title>
      <link>https://community.qlik.com/t5/App-Development/COUNT-IF-vs-COUNT-lt-gt/m-p/1651606#M48592</link>
      <description>&lt;P&gt;Hello Community,&lt;/P&gt;&lt;P&gt;I have a big question since it is drawling some big discrepancies in my thought process.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to count with a condition...&lt;/P&gt;&lt;P&gt;I am under the impression I should be able to do this with either of the two lines of code listed below; however, I get two different results. So my question is how do the two lines of code act differently? Or is there something being done wrong on the back end that would have caused this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Count({&amp;lt;event_type={33,34}&amp;gt;}od_id)&lt;/P&gt;&lt;P&gt;vs&lt;/P&gt;&lt;P&gt;Count(if(event_type=33, od_id) or if(event_type=34, od_id) )&lt;/P&gt;&lt;P&gt;Note I have tried different variations of these.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also tried to diagnose this with only one event_type and still get two different results.&lt;/P&gt;&lt;P&gt;Count({&amp;lt;event_type={33}&amp;gt;}od_id)&amp;nbsp; &amp;nbsp; &amp;nbsp; //will produce 102.1K&lt;/P&gt;&lt;P&gt;vs&amp;nbsp;&lt;/P&gt;&lt;P&gt;Count(if(event_type=33, od_id) )&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // will produce 173.6K&lt;/P&gt;&lt;P&gt;Clarification on how these two formulas are working differently would be greatly appreciated.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 04:00:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/COUNT-IF-vs-COUNT-lt-gt/m-p/1651606#M48592</guid>
      <dc:creator>Josh</dc:creator>
      <dc:date>2024-11-16T04:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: COUNT(IF()) vs COUNT({&lt;&gt;})</title>
      <link>https://community.qlik.com/t5/App-Development/COUNT-IF-vs-COUNT-lt-gt/m-p/1651785#M48610</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Count({SetAnalysis})&lt;/STRONG&gt; = Override the current selection &lt;EM&gt;before&lt;/EM&gt; evaluating the Count expression. This filter action is applied to the whole data model, not row-by-row&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Count(IF())&lt;/STRONG&gt; = Evaluate the IF condition &lt;EM&gt;in each row,&amp;nbsp;&lt;/EM&gt;then apply the Count() function on top of the resulting dataset.&lt;/P&gt;&lt;P&gt;For example, let's say you have the following data model with 2 tables. Note that in &lt;EM&gt;Table 2&lt;/EM&gt; value (1,33) is duplicated.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="test.png" style="width: 274px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/24512i5B40B72E3D0B526C/image-size/large?v=v2&amp;amp;px=999" role="button" title="test.png" alt="test.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;1. Count({&amp;lt;event_type={33}&amp;gt;}od_id)&lt;/STRONG&gt;&lt;/EM&gt;&lt;STRONG&gt; = 2&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN&gt;First Qlik Sense makes a selection on &lt;EM&gt;event_type=33&lt;/EM&gt; (on top of current selection if any)&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Then it performs a count on possible values of &lt;EM&gt;od_id&lt;/EM&gt;, which returns 2&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="test2.png" style="width: 276px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/24518i167AC83A6DB011A7/image-size/large?v=v2&amp;amp;px=999" role="button" title="test2.png" alt="test2.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;2.&amp;nbsp;Count(if(event_type=33, od_id) )&amp;nbsp; &lt;/STRONG&gt;&lt;/EM&gt;&lt;STRONG&gt;= 4&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;First Qlik Sense performs a natural join on tables containing &lt;EM&gt;event_type&lt;/EM&gt; and &lt;EM&gt;od_id.&amp;nbsp;&lt;/EM&gt;Because (1,33) is duplicated in &lt;EM&gt;Table 2,&amp;nbsp;&lt;/EM&gt;it is joined twice.&lt;/LI&gt;&lt;LI&gt;In this joined table, condition&amp;nbsp;&lt;SPAN&gt;&lt;EM&gt;if(event_type=33, od_id) &lt;/EM&gt;is evaluated for each row.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Finally, &lt;EM&gt;Count&lt;/EM&gt; is evaluated on results of the if condition&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;(including the null values) , which returns 4&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="test2.png" style="width: 461px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/24520i96A2742308EF0F5C/image-size/large?v=v2&amp;amp;px=999" role="button" title="test2.png" alt="test2.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;As a thumb rule, if condition should be used when evaluation needs to be done in a row-by-row basis. Otherwise it's better with Set Analysis.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Hope this helps!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;BR,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Vu Nguyen&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 09:43:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/COUNT-IF-vs-COUNT-lt-gt/m-p/1651785#M48610</guid>
      <dc:creator>vunguyenq89</dc:creator>
      <dc:date>2019-11-27T09:43:57Z</dc:date>
    </item>
    <item>
      <title>Re: COUNT(IF()) vs COUNT({&lt;&gt;})</title>
      <link>https://community.qlik.com/t5/App-Development/COUNT-IF-vs-COUNT-lt-gt/m-p/2452766#M98115</link>
      <description>&lt;P&gt;This was a great solution and works perfectly for what I am working on as well.&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2024 13:55:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/COUNT-IF-vs-COUNT-lt-gt/m-p/2452766#M98115</guid>
      <dc:creator>NKOPS1982</dc:creator>
      <dc:date>2024-05-15T13:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: COUNT(IF()) vs COUNT({&lt;&gt;})</title>
      <link>https://community.qlik.com/t5/App-Development/COUNT-IF-vs-COUNT-lt-gt/m-p/2452782#M98119</link>
      <description>&lt;P&gt;In addition to the answer above:&lt;/P&gt;
&lt;P&gt;Generally, the differences between set analysis and an if function are:&lt;BR /&gt;1) Set analysis is a lot faster for large data amounts.&lt;BR /&gt;2) The Count(If(...)) is evaluated row-by-row, i.e. it's slow.&lt;BR /&gt;3) The Count(If(...)) must sometimes first create a temporary table: If "event_8type" and "od_id" reside in different tables. If so, the temporary table may contain more records than the original table, and Count() will return a different result than if you use set analysis.&lt;/P&gt;
&lt;P&gt;Further, the following expression is however incorrect:&lt;BR /&gt;Count(if(event_type=33, od_id) or if(event_type=34, od_id) )&lt;BR /&gt;It should be written like this:&lt;BR /&gt;Count(if(event_type=33 or event_type=34, od_id) )&lt;/P&gt;
&lt;P&gt;See also&lt;BR /&gt;&lt;A href="https://community.qlik.com/t5/Design/Conditional-Aggregations/ba-p/1473362" target="_blank"&gt;https://community.qlik.com/t5/Design/Conditional-Aggregations/ba-p/1473362&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://community.qlik.com/t5/Design/Performance-of-Conditional-Aggregations/ba-p/1463021" target="_blank"&gt;https://community.qlik.com/t5/Design/Performance-of-Conditional-Aggregations/ba-p/1463021&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Finally, are you sure you want to use a nondistinct count? When counting ID:s, you usually want Count(distinct ...).&lt;/P&gt;</description>
      <pubDate>Wed, 15 May 2024 14:17:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/COUNT-IF-vs-COUNT-lt-gt/m-p/2452782#M98119</guid>
      <dc:creator>hic</dc:creator>
      <dc:date>2024-05-15T14:17:12Z</dc:date>
    </item>
  </channel>
</rss>

