<?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 Count distinct on a if-variable condition in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Count-distinct-on-a-if-variable-condition/m-p/7599#M610</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I need some help to set a formula.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have &lt;SPAN style="font-size: 10pt;"&gt;a variable, &lt;SPAN style="font-family: verdana, geneva; font-size: 13.3333px;"&gt;vStock,&lt;/SPAN&gt; that calculate the items stock at a given date:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: verdana, geneva;"&gt;SUM({$&amp;lt;StockDate={"&amp;gt;=&lt;SPAN style="font-size: 13.3333px;"&gt;$(=MIN(DateInit))&lt;/SPAN&gt;"}&amp;gt;*$&amp;lt;StockDate={"&amp;lt;=$(=MIN(DateEnd))"}&amp;gt;} Quantity )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to count the distinct items where stock is greather than zero, for example:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: verdana, geneva;"&gt;COUNT DINTINCT [Item] WHERE [vStock]&amp;gt;0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After some research I find out this formula, but is very slow (and I don't know if it is correct):&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: verdana, geneva;"&gt;COUNT(DISTINCT AGGR(if($(vStock)&amp;gt;0, Item), Item))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: verdana, geneva;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: verdana, geneva;"&gt;There is another, simple way to calculate this without Aggr and/or If statement?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 22 Dec 2021 15:42:54 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2021-12-22T15:42:54Z</dc:date>
    <item>
      <title>Count distinct on a if-variable condition</title>
      <link>https://community.qlik.com/t5/App-Development/Count-distinct-on-a-if-variable-condition/m-p/7599#M610</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I need some help to set a formula.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have &lt;SPAN style="font-size: 10pt;"&gt;a variable, &lt;SPAN style="font-family: verdana, geneva; font-size: 13.3333px;"&gt;vStock,&lt;/SPAN&gt; that calculate the items stock at a given date:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: verdana, geneva;"&gt;SUM({$&amp;lt;StockDate={"&amp;gt;=&lt;SPAN style="font-size: 13.3333px;"&gt;$(=MIN(DateInit))&lt;/SPAN&gt;"}&amp;gt;*$&amp;lt;StockDate={"&amp;lt;=$(=MIN(DateEnd))"}&amp;gt;} Quantity )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to count the distinct items where stock is greather than zero, for example:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: verdana, geneva;"&gt;COUNT DINTINCT [Item] WHERE [vStock]&amp;gt;0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After some research I find out this formula, but is very slow (and I don't know if it is correct):&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: verdana, geneva;"&gt;COUNT(DISTINCT AGGR(if($(vStock)&amp;gt;0, Item), Item))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: verdana, geneva;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: verdana, geneva;"&gt;There is another, simple way to calculate this without Aggr and/or If statement?&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Dec 2021 15:42:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Count-distinct-on-a-if-variable-condition/m-p/7599#M610</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-12-22T15:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: Count distinct on a if-variable condition</title>
      <link>https://community.qlik.com/t5/App-Development/Count-distinct-on-a-if-variable-condition/m-p/7600#M611</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Gabriele,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What about this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Count({&amp;lt;ITEM={"=$(vStock)&amp;gt;0"}&amp;gt;} Distinct ITEM)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 27 Jan 2018 11:44:15 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Count-distinct-on-a-if-variable-condition/m-p/7600#M611</guid>
      <dc:creator>Thiago_Justen_</dc:creator>
      <dc:date>2018-01-27T11:44:15Z</dc:date>
    </item>
  </channel>
</rss>

