<?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: Why does Count(distinct) performe worse (here) than sum(counterField) in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Why-does-Count-distinct-performe-worse-here-than-sum/m-p/453269#M169123</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@Gysbert: Thanks for your reply. &lt;/P&gt;&lt;P&gt;I indeed think your explanation could be right, although I have also seen that the sum in 2 tables was faster than the count distinct. &lt;/P&gt;&lt;P&gt;Perhaps in this case the count has a relative small amount of records to count, causing the count(distinct) to be faster.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately that it is difficult to predict. I liked the "clear and straight rule of the thumb" to always avoid (and replace) count(distinct).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;About your 2nd remark: I don't see how I can add FlagNegative to the RelationTable, because this table contains all relations (unique) and the other table contains payments, where relationKeys exists multiple time (and flagNegative =1 when the payment is &amp;lt;0).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@&lt;A _jive_internal="true" class="jiveTT-hover-user jive-username-link" href="https://community.qlik.com/people/chema.tos" id="jive-742445140585648571465" style="background-color: #ffffff; font-size: 12px; color: #007fc0; font-weight: bold; font-family: Arial; text-align: center;"&gt;José Mª Tos&lt;/A&gt;&lt;/P&gt;&lt;P&gt;What did you mean by your 2nd remark (add conditionals)? &lt;/P&gt;&lt;P&gt;Did you mean a calculation condition (so the object will only be calculated when certain selections are made)? Or other things?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 01 Nov 2012 09:17:54 GMT</pubDate>
    <dc:creator />
    <dc:date>2012-11-01T09:17:54Z</dc:date>
    <item>
      <title>Why does Count(distinct) performe worse (here) than sum(counterField)</title>
      <link>https://community.qlik.com/t5/QlikView/Why-does-Count-distinct-performe-worse-here-than-sum/m-p/453265#M169119</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Qlikcommunity,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yesterday I came across something that surprised me…&lt;/P&gt;&lt;P&gt;I saw a .qvw that was performing _very_ slowly on 1 tab of the document.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After analyzing, I noticed that in 1 chart, there were multiple expressions using count(&lt;STRONG&gt;distinct&lt;/STRONG&gt; fieldname), so I thought this can be done more efficient, using sum(counterfield) (where couterfield is a field in the datamodel loaded with 1 as counterfield).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Surprisingly when I cloned that table, updated all expressions (removing count(distinct) and replaced it with sum(counterfield)… The performance of the NEW chart object seemed even worse than the original one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does anybody have an idea why this could be the case?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The relevant part of the datamodel is like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PaymentsTable (estimated? 50 mln rows?)&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE border="1" cellpadding="3" cellspacing="0" class="jiveBorder" height="69" style="width: 359px; border: 1px solid #000000; height: 71px;"&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;%relationKey&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;Product &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;Amount&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;FlagNegative&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1234&lt;/TD&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;TD&gt;-5&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1234&lt;/TD&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1235&lt;/TD&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RelationTable (about 2.5 mln records)&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE border="1" cellpadding="3" cellspacing="0" class="jiveBorder" height="69" style="width: 359px; border: 1px solid #000000; height: 71px;"&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;%relationKey&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;TH align="center" style="background-color: #6690bc;" valign="middle"&gt;&lt;SPAN style="color: #ffffff;"&gt;&lt;STRONG&gt;RelationCounter&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1234&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1235&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;EM&gt;-----&amp;gt;note that with %relationKey these 2 tables are related in the datamodel&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;-----&amp;gt;note also that %relationKey is unique in the relationstable but NOT unique in the payments table (one to many)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Original expression: &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;count(distinct {&amp;lt;FlagNegative={1}&amp;gt;}&amp;nbsp; %relationKey) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;New expression:&lt;/STRONG&gt; &lt;/P&gt;&lt;P&gt;sum({&amp;lt;FlagNegative={1}&amp;gt;}&amp;nbsp; RelationCounter) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My understanding was that count(distinct) forces Qlikview to work with only 1 CPU instead of all CPU's. Therefore I would have expected the "new expression" to be faster...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My questions&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;[1] - explanation on why new expression does NOT seem faster&lt;/P&gt;&lt;P&gt;[2] - hints on how I can optimize the front-end in another way...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 25 Oct 2012 12:21:19 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Why-does-Count-distinct-performe-worse-here-than-sum/m-p/453265#M169119</guid>
      <dc:creator />
      <dc:date>2012-10-25T12:21:19Z</dc:date>
    </item>
    <item>
      <title>Re: Why does Count(distinct) performe worse (here) than sum(counterField)</title>
      <link>https://community.qlik.com/t5/QlikView/Why-does-Count-distinct-performe-worse-here-than-sum/m-p/453266#M169120</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Anyone ideas on thisone? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is at least the issue I mention clear?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Oct 2012 22:42:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Why-does-Count-distinct-performe-worse-here-than-sum/m-p/453266#M169120</guid>
      <dc:creator />
      <dc:date>2012-10-29T22:42:13Z</dc:date>
    </item>
    <item>
      <title>Re: Why does Count(distinct) performe worse (here) than sum(counterField)</title>
      <link>https://community.qlik.com/t5/QlikView/Why-does-Count-distinct-performe-worse-here-than-sum/m-p/453267#M169121</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;About count and sum, usually its better to use sum so I have no explanation about your first question.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And about the second one, I have the same problem and anybody answered to me, may be with conditionals you could perform a little the objects...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Oct 2012 16:50:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Why-does-Count-distinct-performe-worse-here-than-sum/m-p/453267#M169121</guid>
      <dc:creator>chematos</dc:creator>
      <dc:date>2012-10-31T16:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: Why does Count(distinct) performe worse (here) than sum(counterField)</title>
      <link>https://community.qlik.com/t5/QlikView/Why-does-Count-distinct-performe-worse-here-than-sum/m-p/453268#M169122</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I had to guess, I would say that count(distinct {&amp;lt;FlagNegative={1}&amp;gt;}&amp;nbsp; %relationKey) needs only one table to calculate the count, whereas sum({&amp;lt;FlagNegative={1}&amp;gt;}&amp;nbsp; RelationCounter) needs both tables. And count can probably use an internal index on %relationKey because of the compression qlikview does. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could try adding a FlagNegative field to RelationTable and then try sum over that. Then you won't need the set analysis expression anymore so that should speed things up a bit. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Oct 2012 17:33:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Why-does-Count-distinct-performe-worse-here-than-sum/m-p/453268#M169122</guid>
      <dc:creator>Gysbert_Wassenaar</dc:creator>
      <dc:date>2012-10-31T17:33:46Z</dc:date>
    </item>
    <item>
      <title>Re: Why does Count(distinct) performe worse (here) than sum(counterField)</title>
      <link>https://community.qlik.com/t5/QlikView/Why-does-Count-distinct-performe-worse-here-than-sum/m-p/453269#M169123</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;@Gysbert: Thanks for your reply. &lt;/P&gt;&lt;P&gt;I indeed think your explanation could be right, although I have also seen that the sum in 2 tables was faster than the count distinct. &lt;/P&gt;&lt;P&gt;Perhaps in this case the count has a relative small amount of records to count, causing the count(distinct) to be faster.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately that it is difficult to predict. I liked the "clear and straight rule of the thumb" to always avoid (and replace) count(distinct).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;About your 2nd remark: I don't see how I can add FlagNegative to the RelationTable, because this table contains all relations (unique) and the other table contains payments, where relationKeys exists multiple time (and flagNegative =1 when the payment is &amp;lt;0).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@&lt;A _jive_internal="true" class="jiveTT-hover-user jive-username-link" href="https://community.qlik.com/people/chema.tos" id="jive-742445140585648571465" style="background-color: #ffffff; font-size: 12px; color: #007fc0; font-weight: bold; font-family: Arial; text-align: center;"&gt;José Mª Tos&lt;/A&gt;&lt;/P&gt;&lt;P&gt;What did you mean by your 2nd remark (add conditionals)? &lt;/P&gt;&lt;P&gt;Did you mean a calculation condition (so the object will only be calculated when certain selections are made)? Or other things?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Nov 2012 09:17:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Why-does-Count-distinct-performe-worse-here-than-sum/m-p/453269#M169123</guid>
      <dc:creator />
      <dc:date>2012-11-01T09:17:54Z</dc:date>
    </item>
    <item>
      <title>Re: Why does Count(distinct) performe worse (here) than sum(counterField)</title>
      <link>https://community.qlik.com/t5/QlikView/Why-does-Count-distinct-performe-worse-here-than-sum/m-p/453270#M169124</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, &lt;SPAN style="color: #737373; font-family: Arial; font-size: 12.727272033691406px; background-color: #ffffff;"&gt;the object will only be calculated when certain selections are made&lt;/SPAN&gt;. I saw that your second table could be large because of the 2.5 minutes to load the data, may be is not interesting to show all the rows in the object. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was really thinking more in this thread I started: &lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" class="loading" href="https://community.qlik.com/message/274216#274216"&gt;http://community.qlik.com/message/274216#274216&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you have any ideas, will be apreciated.&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, 01 Nov 2012 11:44:20 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Why-does-Count-distinct-performe-worse-here-than-sum/m-p/453270#M169124</guid>
      <dc:creator>chematos</dc:creator>
      <dc:date>2012-11-01T11:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: Why does Count(distinct) performe worse (here) than sum(counterField)</title>
      <link>https://community.qlik.com/t5/QlikView/Why-does-Count-distinct-performe-worse-here-than-sum/m-p/453271#M169125</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Roberto.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Roberto Postma wrote:&lt;/P&gt;&lt;P&gt;[...]&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;New expression:&lt;/STRONG&gt; &lt;/P&gt;&lt;P&gt;sum({&amp;lt;FlagNegative={1}&amp;gt;}&amp;nbsp; RelationCounter) &lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt; [...] &lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My questions&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;[1] - explanation on why new expression does NOT seem faster&lt;/P&gt;&lt;P&gt;[2] - hints on how I can optimize the front-end in another way...&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;[2]: If the possible values for your FlagNegative is 1 and 0 OR 1 and NULL you can skip the SET and instead use&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_1351772904656279" jivemacro_uid="_1351772904656279"&gt;&lt;P&gt;sum(RelationCounter * FlagNegative)&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.qlik.com/qlik-users/100292"&gt;Vegar Lie Arntsen&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;QlikView consultant at &lt;/EM&gt;&lt;A href="http://www.egbs.se"&gt;egbs consulting ab&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Blog (in Swedish):&lt;/EM&gt; &lt;A href="http://bi-effekten.se"&gt;bi-effekten.se&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Nov 2012 12:37:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Why-does-Count-distinct-performe-worse-here-than-sum/m-p/453271#M169125</guid>
      <dc:creator>Vegar</dc:creator>
      <dc:date>2012-11-01T12:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: Why does Count(distinct) performe worse (here) than sum(counterField)</title>
      <link>https://community.qlik.com/t5/QlikView/Why-does-Count-distinct-performe-worse-here-than-sum/m-p/453272#M169126</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nice idea, I'll try that and see if it is faster.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Nov 2012 12:46:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Why-does-Count-distinct-performe-worse-here-than-sum/m-p/453272#M169126</guid>
      <dc:creator />
      <dc:date>2012-11-01T12:46:30Z</dc:date>
    </item>
  </channel>
</rss>

