<?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() behaving as count(distinct)?? in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1365997#M418071</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I implemented counters as Andrew suggested, but have some weird behavior as a result.&amp;nbsp; Please can anyone explain?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The data structure is:&lt;/P&gt;&lt;P&gt;&lt;IMG class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/162203_pastedImage_2.png" style="max-height: 900px; max-width: 1200px;" /&gt;&lt;/P&gt;&lt;P&gt;I have a simple chart counting consumers by territorysector entry:&lt;/P&gt;&lt;P&gt;&lt;IMG class="jive-image image-2" src="https://community.qlik.com/legacyfs/online/162205_pastedImage_4.png" style="max-height: 900px; max-width: 1200px;" /&gt;&lt;/P&gt;&lt;P&gt;and the result I get is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="jive-image image-3" src="https://community.qlik.com/legacyfs/online/162209_pastedImage_5.png" style="max-height: 900px; max-width: 1200px;" /&gt;&lt;/P&gt;&lt;P&gt;It appears that the same consumer is being counted twice because they have 2 Plan entries, but the whole point of using the 'counter' field was that it would count distinct Consumer table entries only.&amp;nbsp; Why does this not work??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for any help you can give&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Graham&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 04 May 2017 13:55:52 GMT</pubDate>
    <dc:creator />
    <dc:date>2017-05-04T13:55:52Z</dc:date>
    <item>
      <title>Re: Count() behaving as count(distinct)??</title>
      <link>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1365996#M418070</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'd go with adding a specific counter field in the load script, simple and sensible &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/wink.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Andy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Apr 2017 11:38:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1365996#M418070</guid>
      <dc:creator>awhitfield</dc:creator>
      <dc:date>2017-04-25T11:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: Count() behaving as count(distinct)??</title>
      <link>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1365997#M418071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I implemented counters as Andrew suggested, but have some weird behavior as a result.&amp;nbsp; Please can anyone explain?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The data structure is:&lt;/P&gt;&lt;P&gt;&lt;IMG class="jive-image image-1" src="https://community.qlik.com/legacyfs/online/162203_pastedImage_2.png" style="max-height: 900px; max-width: 1200px;" /&gt;&lt;/P&gt;&lt;P&gt;I have a simple chart counting consumers by territorysector entry:&lt;/P&gt;&lt;P&gt;&lt;IMG class="jive-image image-2" src="https://community.qlik.com/legacyfs/online/162205_pastedImage_4.png" style="max-height: 900px; max-width: 1200px;" /&gt;&lt;/P&gt;&lt;P&gt;and the result I get is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG class="jive-image image-3" src="https://community.qlik.com/legacyfs/online/162209_pastedImage_5.png" style="max-height: 900px; max-width: 1200px;" /&gt;&lt;/P&gt;&lt;P&gt;It appears that the same consumer is being counted twice because they have 2 Plan entries, but the whole point of using the 'counter' field was that it would count distinct Consumer table entries only.&amp;nbsp; Why does this not work??&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for any help you can give&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Graham&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 May 2017 13:55:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1365997#M418071</guid>
      <dc:creator />
      <dc:date>2017-05-04T13:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: Count() behaving as count(distinct)??</title>
      <link>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1365998#M418072</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;why not:&lt;/P&gt;&lt;P&gt;count(distinct consumer_id)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 May 2017 13:59:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1365998#M418072</guid>
      <dc:creator>m_woolf</dc:creator>
      <dc:date>2017-05-04T13:59:52Z</dc:date>
    </item>
    <item>
      <title>Re: Count() behaving as count(distinct)??</title>
      <link>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1365999#M418073</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;not sure but if you want result of count() match with count(distinct ) you have to normalize your data model.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 May 2017 14:06:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1365999#M418073</guid>
      <dc:creator>PrashantSangle</dc:creator>
      <dc:date>2017-05-04T14:06:40Z</dc:date>
    </item>
    <item>
      <title>Re: Count() behaving as count(distinct)??</title>
      <link>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1366000#M418074</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you should be using Count(Distinct&amp;nbsp; if you don't want to use Count(Distinct .(which is actually faster than count!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create a separate table&amp;nbsp; as below&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load Distinct Customer_ID, 1 as Customer_Counter&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from Resident Consumer&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then change your expression to Sum(Counter)&amp;nbsp; or count(Counter)&lt;/P&gt;&lt;P&gt;&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>Thu, 04 May 2017 14:16:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1366000#M418074</guid>
      <dc:creator>vinieme12</dc:creator>
      <dc:date>2017-05-04T14:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: Count() behaving as count(distinct)??</title>
      <link>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1366001#M418075</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, the original thread is &lt;A _jive_internal="true" href="https://community.qlik.com/message/1256371?et=watches.email.thread#1256371" title="https://community.qlik.com/message/1256371?et=watches.email.thread#1256371"&gt;https://community.qlik.com/message/1256371?et=watches.email.thread#1256371&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I branched off this discussion rather than reopening that thread, but if you check it out you can see that I was originally using count() with a key field as you suggest, and getting unpredictable results (counts of 1 for everything). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was recommended to add a counter field (with content = '1') to tables I wanted to count instead to ensure I was counting from the correct table.&amp;nbsp; I understood that was because counting a key field can give a result according to its presence in a linked table, rather than its 'primary' table?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 May 2017 14:17:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1366001#M418075</guid>
      <dc:creator />
      <dc:date>2017-05-04T14:17:55Z</dc:date>
    </item>
    <item>
      <title>Re: Count() behaving as count(distinct)??</title>
      <link>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1366002#M418076</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Vineeth.&amp;nbsp; Sorry, I don't understand.&amp;nbsp; Why would a separate table linked 1 to 1 to the consumer table behave any differently to adding a counter field to the consumer table itself?&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This branch comes off thread 1256371 (I included a link in an earlier post but that's "being moderated" - I presume because it's a link...)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the original post I was asking about why when I applied a count() to a key field I got a count of 1 for everything. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was recommended to add a counter field (with content = '1') to tables I wanted to count instead, to ensure I was counting from the correct table.&amp;nbsp; I understood that was because counting a key field can give a result according to its presence in a linked table, rather than its 'primary' table?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I presume DISTINCT won't help in a case where I'm getting 1 for everything...?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 May 2017 14:36:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1366002#M418076</guid>
      <dc:creator />
      <dc:date>2017-05-04T14:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: Count() behaving as count(distinct)??</title>
      <link>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1366003#M418077</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Because the second table &lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;will only hold Distinct Values!&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;If it's difficult to understand try the below sample&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fact:&lt;/P&gt;&lt;P&gt;Load Person,1 as PersonCounter inline [&lt;/P&gt;&lt;P&gt;Person&lt;/P&gt;&lt;P&gt;A&lt;/P&gt;&lt;P&gt;A&lt;/P&gt;&lt;P&gt;A&lt;/P&gt;&lt;P&gt;B&lt;/P&gt;&lt;P&gt;B&lt;/P&gt;&lt;P&gt;c&lt;/P&gt;&lt;P&gt;c&lt;/P&gt;&lt;P&gt;c&lt;/P&gt;&lt;P&gt;d&lt;/P&gt;&lt;P&gt;d&lt;/P&gt;&lt;P&gt;e&lt;/P&gt;&lt;P&gt;e];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DistinctPerson:&lt;/P&gt;&lt;P&gt;Load * &lt;STRONG&gt;Distinct&lt;/STRONG&gt; Person,1 as Counter&lt;/P&gt;&lt;P&gt;Resident &lt;SPAN style="font-size: 13.3333px;"&gt;fact&lt;/SPAN&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now&amp;nbsp; Sum(&lt;SPAN style="font-size: 13.3333px;"&gt;Counter&lt;/SPAN&gt;) or &lt;SPAN style="font-size: 13.3333px;"&gt;count(&lt;/SPAN&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;Counter&lt;/SPAN&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;)&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; is unique count of people&lt;/P&gt;&lt;P&gt;and Sum(PersonCounter) or &lt;SPAN style="font-size: 13.3333px;"&gt;Count(PersonCounter) &lt;/SPAN&gt;&amp;nbsp; is the count of instances the person occurs in Fact&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 May 2017 14:46:00 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1366003#M418077</guid>
      <dc:creator>vinieme12</dc:creator>
      <dc:date>2017-05-04T14:46:00Z</dc:date>
    </item>
    <item>
      <title>Re: Count() behaving as count(distinct)??</title>
      <link>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1366004#M418078</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Vineeth.&amp;nbsp; I should have pointed out - my Consumer table already contains distinct values - my database is fully normalized &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 May 2017 14:52:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1366004#M418078</guid>
      <dc:creator />
      <dc:date>2017-05-04T14:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: Count() behaving as count(distinct)??</title>
      <link>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1366005#M418079</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How do you create the counter field? Could you post your script?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You should get a count of 1 if your consumer table does only show a record per consumer id.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you post your QVW? Maybe with scrambled data, if needed:&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.qlik.com/docs/DOC-1290"&gt;Preparing examples for Upload - Reduction and Data Scrambling&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.qlik.com/docs/DOC-16454"&gt;Uploading a Sample&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But after all, if you are really interested in the number of distinct consumers, I would suggest using&lt;/P&gt;&lt;P&gt;Count(DISTINCT consumer_id)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 May 2017 10:15:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1366005#M418079</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2017-05-05T10:15:30Z</dc:date>
    </item>
    <item>
      <title>Re: Count() behaving as count(distinct)??</title>
      <link>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1366006#M418080</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry Stefan/everybody - I finally spotted the problem.&amp;nbsp; I was convinced there was no chance of this, but some duplicates had got into the consumer table as part of the data preparation process.. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Great news really though - gives me confidence that the counter method will work consistently once I've resolved the duplication!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again for your assistance in resolving this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Graham&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 May 2017 10:47:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Re-Count-behaving-as-count-distinct/m-p/1366006#M418080</guid>
      <dc:creator />
      <dc:date>2017-05-05T10:47:24Z</dc:date>
    </item>
  </channel>
</rss>

