<?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 Counting Distinct across dimensions in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Counting-Distinct-across-dimensions/m-p/1112919#M367839</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;Say I have a list of clients, and I want to create a count of unique client attendances over 2 years by age group.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using a dimension of AGE_GROUP (grouping in 10 year blocks) and an expression of&lt;/P&gt;&lt;P&gt;COUNT(DISTINCT CLIENT_ID) (where the CLIENT_ID is unique to a client), I end up with something like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 196px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl65" height="17" width="98"&gt;AGE_BAND&lt;/TD&gt;&lt;TD class="xl65" style="border-left: none;" width="98"&gt;# Clients&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl68" height="17" style="border-top: none;"&gt;40 - 49&lt;/TD&gt;&lt;TD align="right" class="xl69" style="border-top: none; border-left: none;"&gt;2718&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl68" height="17" style="border-top: none;"&gt;50 - 59&lt;/TD&gt;&lt;TD align="right" class="xl69" style="border-top: none; border-left: none;"&gt;3390&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl68" height="17" style="border-top: none;"&gt;60 - 69&lt;/TD&gt;&lt;TD align="right" class="xl69" style="border-top: none; border-left: none;"&gt;2216&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl68" height="17" style="border-top: none;"&gt;70 - 74&lt;/TD&gt;&lt;TD align="right" class="xl69" style="border-top: none; border-left: none;"&gt;439&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl68" height="17" style="border-top: none;"&gt;75 - 79&lt;/TD&gt;&lt;TD align="right" class="xl69" style="border-top: none; border-left: none;"&gt;129&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl68" height="17" style="border-top: none;"&gt;80+&lt;/TD&gt;&lt;TD align="right" class="xl69" style="border-top: none; border-left: none;"&gt;31&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl66" height="17" style="border-top: none;"&gt;&lt;STRONG&gt;40+&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none;"&gt;8875&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, from this you can see that the sum of the age groups (excluding 40+, it being the total) comes to 8923.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The number of distinct clients is in fact 8875, but there is an issue in that a client who attended when they were in the 40-49 range who then, within the two-year period attended when they were in the 50-59 period would be counted twice.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I calculate distinct clients by age band factoring for where that client attended while in an earlier age band?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lee&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 16 Aug 2016 06:49:23 GMT</pubDate>
    <dc:creator />
    <dc:date>2016-08-16T06:49:23Z</dc:date>
    <item>
      <title>Counting Distinct across dimensions</title>
      <link>https://community.qlik.com/t5/QlikView/Counting-Distinct-across-dimensions/m-p/1112919#M367839</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;Say I have a list of clients, and I want to create a count of unique client attendances over 2 years by age group.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using a dimension of AGE_GROUP (grouping in 10 year blocks) and an expression of&lt;/P&gt;&lt;P&gt;COUNT(DISTINCT CLIENT_ID) (where the CLIENT_ID is unique to a client), I end up with something like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 196px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl65" height="17" width="98"&gt;AGE_BAND&lt;/TD&gt;&lt;TD class="xl65" style="border-left: none;" width="98"&gt;# Clients&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl68" height="17" style="border-top: none;"&gt;40 - 49&lt;/TD&gt;&lt;TD align="right" class="xl69" style="border-top: none; border-left: none;"&gt;2718&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl68" height="17" style="border-top: none;"&gt;50 - 59&lt;/TD&gt;&lt;TD align="right" class="xl69" style="border-top: none; border-left: none;"&gt;3390&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl68" height="17" style="border-top: none;"&gt;60 - 69&lt;/TD&gt;&lt;TD align="right" class="xl69" style="border-top: none; border-left: none;"&gt;2216&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl68" height="17" style="border-top: none;"&gt;70 - 74&lt;/TD&gt;&lt;TD align="right" class="xl69" style="border-top: none; border-left: none;"&gt;439&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl68" height="17" style="border-top: none;"&gt;75 - 79&lt;/TD&gt;&lt;TD align="right" class="xl69" style="border-top: none; border-left: none;"&gt;129&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl68" height="17" style="border-top: none;"&gt;80+&lt;/TD&gt;&lt;TD align="right" class="xl69" style="border-top: none; border-left: none;"&gt;31&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl66" height="17" style="border-top: none;"&gt;&lt;STRONG&gt;40+&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD align="right" class="xl67" style="border-top: none;"&gt;8875&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, from this you can see that the sum of the age groups (excluding 40+, it being the total) comes to 8923.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The number of distinct clients is in fact 8875, but there is an issue in that a client who attended when they were in the 40-49 range who then, within the two-year period attended when they were in the 50-59 period would be counted twice.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I calculate distinct clients by age band factoring for where that client attended while in an earlier age band?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lee&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Aug 2016 06:49:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Counting-Distinct-across-dimensions/m-p/1112919#M367839</guid>
      <dc:creator />
      <dc:date>2016-08-16T06:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Distinct across dimensions</title>
      <link>https://community.qlik.com/t5/QlikView/Counting-Distinct-across-dimensions/m-p/1112920#M367840</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would suggest creating a flag in the script for clients 1st visit. So Something like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;LOAD &lt;SPAN style="font-size: 13.3333px;"&gt;CLIENT_ID&lt;/SPAN&gt;,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If(&lt;SPAN style="font-size: 13.3333px;"&gt;CLIENT_ID&lt;/SPAN&gt;= Previous(&lt;SPAN style="font-size: 13.3333px;"&gt;CLIENT_ID&lt;/SPAN&gt;), 0, 1) as Flag&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Resident ....&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Order By Client, Age;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now use this as your expression&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Count(DISTINCT {&amp;lt;Flag&amp;nbsp; = {1}&amp;gt;} CLIENT_ID)&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Aug 2016 09:44:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Counting-Distinct-across-dimensions/m-p/1112920#M367840</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2016-08-16T09:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Distinct across dimensions</title>
      <link>https://community.qlik.com/t5/QlikView/Counting-Distinct-across-dimensions/m-p/1112921#M367841</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Sunny - In this case, this is not going to work (I don't think - not without some refinement). The analysis is performed over 2-year blocks, so the end table would look like: &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" height="232" style="width: 546px; height: 232px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD height="15" width="85"&gt;&lt;/TD&gt;&lt;TD width="74"&gt;2009–2010&lt;/TD&gt;&lt;TD width="74"&gt;2010–2011&lt;/TD&gt;&lt;TD width="74"&gt;2011–2012&lt;/TD&gt;&lt;TD width="74"&gt;2012–2013&lt;/TD&gt;&lt;TD width="74"&gt;2013–2014&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="15"&gt;40–49 years &lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="15"&gt;50–59 years &lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="15"&gt;60–69 years&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="15"&gt;70–79 yrs&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="15"&gt;80+ years&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;TD&gt;xx&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="xl90" height="15"&gt;&lt;STRONG&gt;Total 40+ Years&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl90"&gt;Sum of above&lt;/TD&gt;&lt;TD class="xl90"&gt;Sum of above&lt;/TD&gt;&lt;TD class="xl90"&gt;Sum of above&lt;/TD&gt;&lt;TD class="xl90"&gt;Sum of above&lt;/TD&gt;&lt;TD class="xl90"&gt;&lt;P&gt;Sum of above&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now the issue lies in that a client who attends in 2009 for the first time, and then in 2010, and then in 2011 needs to be only counted once in each block, irrespective of the age at attendance. For example, the client is 49 at their 2009 attendance and 50 at their 2010 attendance, then the count should only have them at the 40-49 band for the 2009-2010 column, but then they should also be counted once again in the 50-59 years band of the 2010-2011 column, and so forth.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suspect I will have to build a new table to factor for this, but was hoping that set analysis could handle it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any thoughts or suggestions on an approach appreciated,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Lee&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Aug 2016 23:15:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Counting-Distinct-across-dimensions/m-p/1112921#M367841</guid>
      <dc:creator />
      <dc:date>2016-08-16T23:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Distinct across dimensions</title>
      <link>https://community.qlik.com/t5/QlikView/Counting-Distinct-across-dimensions/m-p/1112922#M367842</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think this could still work but will have to be played around with. If you can provide few sample rows of data with the expected output, someone here might be able to help you achieve your desired output.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Sunny&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Aug 2016 23:28:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Counting-Distinct-across-dimensions/m-p/1112922#M367842</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2016-08-16T23:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: Counting Distinct across dimensions</title>
      <link>https://community.qlik.com/t5/QlikView/Counting-Distinct-across-dimensions/m-p/1112923#M367843</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay, thought I'd post an update on this - I did have to create a new structure around this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For anyone who has to deal with a similar issue, my methodology was this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1: Get the minimum and maximum years available&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt; LET vMinYr = YEAR($(vMinDate));&lt;/P&gt;&lt;P&gt; LET vMaxYr = YEAR($(vMaxDate));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2: Do a loop from through the years&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;FOR i =Num#($(vMinYr), '####') to Num($(vMaxYr))&lt;/P&gt;&lt;P&gt;LET j =Num#($(i), '####')+2; //To ensure 2 year blocks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;3: Create a temporary table of sorted values&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;CLI_TMP:&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Fields],&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Text($(i)) &amp;amp; '-' &amp;amp; Text(Num#($(i), '####')+1) AS ATTENDANCE_RANGE, --i.e., 2013 - 2014&lt;/P&gt;&lt;P&gt;RESIDENT CLIENT_ATTENDANCES&lt;/P&gt;&lt;P&gt;WHERE Num#(YEAR(ATTENDANCE_DATE))&amp;gt;=$(i) AND Num#(YEAR(ATTENDANCE_DATE)) &amp;lt; $(j)&lt;/P&gt;&lt;P&gt;ORDER BY CLI_ID ASC, ATTENDANCE_DATE ASC&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;4: Screen the temp table for duplicates into the final table - I needed to do this because using peek/previous in the above build didn't seem to filter duplicates properly&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [Fields]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF(CLI_ID &amp;lt;&amp;gt; Previous(CLI_ID),1,0) AS ATTENDANCE_FLAG --&lt;/P&gt;&lt;P&gt;RESIDENT CLI_TMP&lt;/P&gt;&lt;P&gt;ORDER BY CLI_ID ASC, ATTENDANCE_DATE ASC -- to be sure to be sure...&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;5: Drop the tmp table&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Drop table CLI_TMP&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;Next i;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's a bit convoluted but it works. It would be nice if there was a more elegant solutions though.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Aug 2016 00:51:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Counting-Distinct-across-dimensions/m-p/1112923#M367843</guid>
      <dc:creator />
      <dc:date>2016-08-31T00:51:25Z</dc:date>
    </item>
  </channel>
</rss>

