<?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 distinct count issue in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/distinct-count-issue/m-p/384252#M491634</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;i have a data input about products, each with a number of product versiones.&lt;/P&gt;&lt;P&gt;each version has a status (enabled, disabled, deleted) and a product that had a deleted status in one of its versions cannot move to enabled in a later version.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;now, im trying to calculate the total number of distinct products that are enabled.&lt;/P&gt;&lt;P&gt;calculating count (distinct product id) and filtering on status will not be good since if a product is deleted at its latest version, it still had an earlier version enabled so the filter will keep the earlier versions and the count distinct will count the product though it shouldnt....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data looks somthing like this:&lt;/P&gt;&lt;TABLE border="1" cellpadding="3" cellspacing="0" class="jiveBorder" style="width: 100%; border: 1px solid #000000;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;product id&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;STRONG style="color: #ffffff; text-align: -webkit-center; background-color: #6690bc;"&gt;product version id&lt;/STRONG&gt;&lt;BR /&gt;&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;STRONG style="color: #ffffff; text-align: -webkit-center; background-color: #6690bc;"&gt;status&lt;/STRONG&gt;&lt;BR /&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;enabled&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;enabled&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;enabled&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;456789&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;enabled&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;456789&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;deleted&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;789000&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;enabled&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;789000&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;enabled&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;so, for the above sample my count should return '2'&amp;nbsp; since second product was deleted on its second version but a regular coun distinct will return 3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i was thinking about somthing like selecting the max version per product and for that filter out the deleted and only than count the products.&lt;/P&gt;&lt;P&gt;any ideas?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 05 Sep 2012 09:06:27 GMT</pubDate>
    <dc:creator />
    <dc:date>2012-09-05T09:06:27Z</dc:date>
    <item>
      <title>distinct count issue</title>
      <link>https://community.qlik.com/t5/QlikView/distinct-count-issue/m-p/384252#M491634</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;i have a data input about products, each with a number of product versiones.&lt;/P&gt;&lt;P&gt;each version has a status (enabled, disabled, deleted) and a product that had a deleted status in one of its versions cannot move to enabled in a later version.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;now, im trying to calculate the total number of distinct products that are enabled.&lt;/P&gt;&lt;P&gt;calculating count (distinct product id) and filtering on status will not be good since if a product is deleted at its latest version, it still had an earlier version enabled so the filter will keep the earlier versions and the count distinct will count the product though it shouldnt....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data looks somthing like this:&lt;/P&gt;&lt;TABLE border="1" cellpadding="3" cellspacing="0" class="jiveBorder" style="width: 100%; border: 1px solid #000000;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;product id&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;STRONG style="color: #ffffff; text-align: -webkit-center; background-color: #6690bc;"&gt;product version id&lt;/STRONG&gt;&lt;BR /&gt;&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;STRONG style="color: #ffffff; text-align: -webkit-center; background-color: #6690bc;"&gt;status&lt;/STRONG&gt;&lt;BR /&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;enabled&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;enabled&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123456&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;enabled&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;456789&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;enabled&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;456789&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;deleted&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;789000&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;enabled&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;789000&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;enabled&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;so, for the above sample my count should return '2'&amp;nbsp; since second product was deleted on its second version but a regular coun distinct will return 3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i was thinking about somthing like selecting the max version per product and for that filter out the deleted and only than count the products.&lt;/P&gt;&lt;P&gt;any ideas?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Sep 2012 09:06:27 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/distinct-count-issue/m-p/384252#M491634</guid>
      <dc:creator />
      <dc:date>2012-09-05T09:06:27Z</dc:date>
    </item>
    <item>
      <title>Re: distinct count issue</title>
      <link>https://community.qlik.com/t5/QlikView/distinct-count-issue/m-p/384253#M491635</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;An expression like the following will work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13468370415592745" jivemacro_uid="_13468370415592745"&gt;&lt;P&gt;=Count(Aggr(Only(If(Aggr(FirstSortedValue(status, -[product version id]), [product id]) &amp;lt;&amp;gt; 'deleted', [product id])), [product id]))&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, it's quite tricky and depending on the number of rows your application is handling, it may take a long time to calculate. So, you rather get the value in the script, using Peek() and Previous() functions:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13468370415587896" jivemacro_uid="_13468370415587896"&gt;&lt;P&gt;Original:&lt;/P&gt;&lt;P&gt;LOAD [product id], &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [product version id], &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; status&lt;/P&gt;&lt;P&gt;FROM&lt;/P&gt;&lt;P&gt;Distinct.xls&lt;/P&gt;&lt;P&gt;(biff, embedded labels, table is Sheet1$);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Final:&lt;/P&gt;&lt;P&gt;LOAD *,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If([product id] &amp;lt;&amp;gt; Previous([product id]), If(status = 'deleted', 0, 1)) AS ProductCheck&lt;/P&gt;&lt;P&gt;RESIDENT Original // do not use resident loads with large tables&lt;/P&gt;&lt;P&gt;ORDER BY [product id], [product version id] DESC;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DROP TABLE Original;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The expression now is as simple as &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_13468370415587694" jivemacro_uid="_13468370415587694"&gt;&lt;P&gt;Sum(ProductCheck)&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Miguel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Sep 2012 09:23:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/distinct-count-issue/m-p/384253#M491635</guid>
      <dc:creator>Miguel_Angel_Baeyens</dc:creator>
      <dc:date>2012-09-05T09:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: distinct count issue</title>
      <link>https://community.qlik.com/t5/QlikView/distinct-count-issue/m-p/384254#M491636</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;I might have misunderstood your question but would something like this solve your problem?&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; Count({$&amp;lt;status={enabled},[product version id]={$(=Max([product version id]))&amp;gt;} DISTINCT [product id])&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Sep 2012 09:31:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/distinct-count-issue/m-p/384254#M491636</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-09-05T09:31:54Z</dc:date>
    </item>
    <item>
      <title>Re: distinct count issue</title>
      <link>https://community.qlik.com/t5/QlikView/distinct-count-issue/m-p/384255#M491637</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;niromo,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i think your solution will not be good enough since it compares the max version id, not taking underconsideration that each product has a different max version id.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;miguel,&lt;/P&gt;&lt;P&gt;thank you for your reply. i'll give it a try and let you know what i come up with...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Sep 2012 09:58:43 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/distinct-count-issue/m-p/384255#M491637</guid>
      <dc:creator />
      <dc:date>2012-09-05T09:58:43Z</dc:date>
    </item>
  </channel>
</rss>

