<?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: Only count first occurence during a year in set analysis in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Only-count-first-occurence-during-a-year-in-set-analysis/m-p/2124487#M91505</link>
    <description>&lt;P&gt;G'day&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/237020"&gt;@alliedarmour&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;I like to get the processing done in the load script. Something like this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;MapFirstVisit:
mapping
load CustID &amp;amp; Year as [CustID-Year]
   , min( Month ) as [First Visit]
from Visit.qvd (qvd) group by CustID, Year;

Visit: 
load CustID, Year, Month 
   , if( Month = applymap( 'MapFirstVisit', CustID &amp;amp; Year ), 1, 0 ) as [First Visit]
from Visit.qvd (qvd);

&lt;/LI-CODE&gt;
&lt;P&gt;Then the Set Analysis becomes very simple:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Count( {$&amp;lt;[First Visit] = {1}&amp;gt;} DISTINCT CustID )&lt;/LI-CODE&gt;
&lt;P&gt;The advantage is that this processing happens in the overnight load and not when the user selects a sheet or filter. It also makes it much easier to use in multiple visualisations. I hope this is useful.&lt;/P&gt;
&lt;P&gt;Cheers, Barnaby.&lt;/P&gt;
&lt;P&gt;P.S. I wasn't 100% sure but I understand that you want the first visit per Customer per Year.&lt;/P&gt;</description>
    <pubDate>Mon, 02 Oct 2023 22:13:59 GMT</pubDate>
    <dc:creator>barnabyd</dc:creator>
    <dc:date>2023-10-02T22:13:59Z</dc:date>
    <item>
      <title>Only count first occurence during a year in set analysis</title>
      <link>https://community.qlik.com/t5/App-Development/Only-count-first-occurence-during-a-year-in-set-analysis/m-p/2124246#M91489</link>
      <description>&lt;P&gt;Hey,&lt;/P&gt;
&lt;P&gt;I want to achieve the following in my straight table: Count records which appear in specific months during the year, but only count them if this is their &lt;STRONG&gt;first occurence&lt;/STRONG&gt; during the year.&lt;/P&gt;
&lt;P&gt;So for example: A customer visits a store in February, but paid a visit in January aswell. This customer should be counted for January (as it's the first visit of the year) but &lt;STRONG&gt;NOT&lt;/STRONG&gt; for february.&lt;/P&gt;
&lt;P&gt;Currently I'm achieving this by using the P() and E() functions, which works but is - in my opinion - a bit cumbersome with all those months you have to track during the whole year.&lt;/P&gt;
&lt;P&gt;The example above looks like this with set analysis:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt; Count({$&amp;lt;CustID = P({1&amp;lt;Month= {"Jan.", "Feb."}, Year = {$(=Only(Year))} &amp;gt;}) * &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;E({1&amp;lt;Month = {"Jan."}, Year = {$(=Only(Year))}})&amp;gt;} DISTINCT CustID&lt;/STRONG&gt;)&lt;/P&gt;
&lt;P&gt;It's working and the values are correct - but I wonder if there is a more "elegant" solution to this. I tried with Min(Month), but the results didn't match.&lt;/P&gt;
&lt;P&gt;Any ideas? Thanks for any input!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 09:53:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Only-count-first-occurence-during-a-year-in-set-analysis/m-p/2124246#M91489</guid>
      <dc:creator>alliedarmour</dc:creator>
      <dc:date>2023-10-02T09:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: Only count first occurence during a year in set analysis</title>
      <link>https://community.qlik.com/t5/App-Development/Only-count-first-occurence-during-a-year-in-set-analysis/m-p/2124260#M91492</link>
      <description>&lt;P&gt;Perhaps this.&lt;/P&gt;
&lt;P&gt;Count({$&amp;lt;CustID = {"=Aggr(Min(Month), CustID, Year)"}&amp;gt;} DISTINCT CustID)&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 10:35:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Only-count-first-occurence-during-a-year-in-set-analysis/m-p/2124260#M91492</guid>
      <dc:creator>BrunPierre</dc:creator>
      <dc:date>2023-10-02T10:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: Only count first occurence during a year in set analysis</title>
      <link>https://community.qlik.com/t5/App-Development/Only-count-first-occurence-during-a-year-in-set-analysis/m-p/2124286#M91494</link>
      <description>&lt;P&gt;Doesn't give me the same results, surprisingly. I tried something similar before.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 11:36:08 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Only-count-first-occurence-during-a-year-in-set-analysis/m-p/2124286#M91494</guid>
      <dc:creator>alliedarmour</dc:creator>
      <dc:date>2023-10-02T11:36:08Z</dc:date>
    </item>
    <item>
      <title>Re: Only count first occurence during a year in set analysis</title>
      <link>https://community.qlik.com/t5/App-Development/Only-count-first-occurence-during-a-year-in-set-analysis/m-p/2124305#M91495</link>
      <description>&lt;P&gt;If this is always limited to a single year (which it appears to be, since you have a set in there for Only(Year)), why not just a regular count distinct?&lt;/P&gt;
&lt;P&gt;If Month is a dimension, and you're looking for *new* customers for that month, probably the cleanest approach is to count distinct for the entire year up to and including that month, and subtract the Above() version of the same thing (or write it out the set for start of year to one month prior, which can be done with two aggregations or within the set itself using set subtraction - Set1(Start of total period to Endmonth of current date) - Set2(Start of total period to endmonth of AddMonths(Current date,-1))&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 12:57:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Only-count-first-occurence-during-a-year-in-set-analysis/m-p/2124305#M91495</guid>
      <dc:creator>Or</dc:creator>
      <dc:date>2023-10-02T12:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: Only count first occurence during a year in set analysis</title>
      <link>https://community.qlik.com/t5/App-Development/Only-count-first-occurence-during-a-year-in-set-analysis/m-p/2124487#M91505</link>
      <description>&lt;P&gt;G'day&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/237020"&gt;@alliedarmour&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;I like to get the processing done in the load script. Something like this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;MapFirstVisit:
mapping
load CustID &amp;amp; Year as [CustID-Year]
   , min( Month ) as [First Visit]
from Visit.qvd (qvd) group by CustID, Year;

Visit: 
load CustID, Year, Month 
   , if( Month = applymap( 'MapFirstVisit', CustID &amp;amp; Year ), 1, 0 ) as [First Visit]
from Visit.qvd (qvd);

&lt;/LI-CODE&gt;
&lt;P&gt;Then the Set Analysis becomes very simple:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Count( {$&amp;lt;[First Visit] = {1}&amp;gt;} DISTINCT CustID )&lt;/LI-CODE&gt;
&lt;P&gt;The advantage is that this processing happens in the overnight load and not when the user selects a sheet or filter. It also makes it much easier to use in multiple visualisations. I hope this is useful.&lt;/P&gt;
&lt;P&gt;Cheers, Barnaby.&lt;/P&gt;
&lt;P&gt;P.S. I wasn't 100% sure but I understand that you want the first visit per Customer per Year.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2023 22:13:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Only-count-first-occurence-during-a-year-in-set-analysis/m-p/2124487#M91505</guid>
      <dc:creator>barnabyd</dc:creator>
      <dc:date>2023-10-02T22:13:59Z</dc:date>
    </item>
    <item>
      <title>Re: Only count first occurence during a year in set analysis</title>
      <link>https://community.qlik.com/t5/App-Development/Only-count-first-occurence-during-a-year-in-set-analysis/m-p/2124816#M91544</link>
      <description>&lt;P&gt;That's what I had before, which was even more cumbersome cause you have to do something like &lt;EM&gt;&lt;STRONG&gt;Set1(Jan, Feb, Mar,Apr,May,...) - Set2(Jan,Feb,Mar,Apr,...)&lt;/STRONG&gt;&lt;/EM&gt;, so I replaced it with my P() and E()-Version.&lt;/P&gt;
&lt;P&gt;The straight table always - per definition - shows the whole year, so the user doesn't select a month or specific period apart from a year, so I can't use the selection or a current date, unfortunately.&lt;/P&gt;
&lt;P&gt;If you could provide a more "clean" code example I'd totally use it, but that's why I don't look for a &lt;STRONG&gt;&lt;EM&gt;How to do it&lt;/EM&gt;&lt;/STRONG&gt; (cause I know that) but rather for a &lt;EM&gt;&lt;STRONG&gt;Is there a more code-saving, elegant solution to do it&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Thanks anyway for your input &amp;amp; time!&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 17:20:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Only-count-first-occurence-during-a-year-in-set-analysis/m-p/2124816#M91544</guid>
      <dc:creator>alliedarmour</dc:creator>
      <dc:date>2023-10-03T17:20:35Z</dc:date>
    </item>
    <item>
      <title>Re: Only count first occurence during a year in set analysis</title>
      <link>https://community.qlik.com/t5/App-Development/Only-count-first-occurence-during-a-year-in-set-analysis/m-p/2124817#M91545</link>
      <description>&lt;P&gt;Hey Barnaby,&lt;/P&gt;
&lt;P&gt;yeah, you got me exactly right!&lt;/P&gt;
&lt;P&gt;That's a quite elegant solution, will try it out tomorrow when I'm back at work, thanks!&lt;/P&gt;
&lt;P&gt;Had also the idea to do it in background processing, but I didn't consider a MAPPING solution&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Oct 2023 17:18:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Only-count-first-occurence-during-a-year-in-set-analysis/m-p/2124817#M91545</guid>
      <dc:creator>alliedarmour</dc:creator>
      <dc:date>2023-10-03T17:18:25Z</dc:date>
    </item>
  </channel>
</rss>

