<?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: Count ONLY if 2 named services happen on same date in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Count-ONLY-if-2-named-services-happen-on-same-date/m-p/1908903#M74925</link>
    <description>&lt;P&gt;Pure gold. Thank you both!&lt;/P&gt;</description>
    <pubDate>Wed, 23 Mar 2022 16:06:03 GMT</pubDate>
    <dc:creator>mbeccaria</dc:creator>
    <dc:date>2022-03-23T16:06:03Z</dc:date>
    <item>
      <title>Count ONLY if 2 named services happen on same date</title>
      <link>https://community.qlik.com/t5/App-Development/Count-ONLY-if-2-named-services-happen-on-same-date/m-p/1908334#M74877</link>
      <description>&lt;P&gt;I'm in a healthcare field using Qlik sense and I want to be able to count how many clients receive both service A and service B on the same day. If they received them on different days, don't count it.&lt;/P&gt;
&lt;P&gt;So, in the table below, Client X received both service A &lt;U&gt;&lt;EM&gt;AND&lt;/EM&gt; &lt;/U&gt;B on 1/1/2022. No other client received service A and B on the same day, &lt;STRONG&gt;so the result should be 1&lt;/STRONG&gt;. I tried the code below and it wasn't working. Any help on how to approach this?&lt;/P&gt;
&lt;LI-CODE lang="java"&gt;=count(
	{&amp;lt;[Service Name] = {"A","B"}&amp;gt;}
    aggr
    	(Count
            ([Service Date]),
            [Client ID],
            [Service Date],
            [Service Name]
       	)
    )&lt;/LI-CODE&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;Date&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;Client&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;Service&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;&lt;EM&gt;&lt;STRONG&gt;1/1/2022&lt;/STRONG&gt;&lt;/EM&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;&lt;EM&gt;&lt;STRONG&gt;X&lt;/STRONG&gt;&lt;/EM&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;&lt;EM&gt;&lt;STRONG&gt;A&lt;/STRONG&gt;&lt;/EM&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;&lt;EM&gt;&lt;STRONG&gt;1/1/2022&lt;/STRONG&gt;&lt;/EM&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;&lt;EM&gt;&lt;STRONG&gt;X&lt;/STRONG&gt;&lt;/EM&gt;&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;&lt;EM&gt;&lt;STRONG&gt;B&lt;/STRONG&gt;&lt;/EM&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;1/3/2022&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;Y&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;1/3/2022&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;Y&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;C&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;1/4/2022&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;X&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;1/5/2022&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;X&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;B&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;1/6/2022&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;X&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;1/7/2022&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;X&lt;/TD&gt;
&lt;TD width="33.333333333333336%" height="25px"&gt;B&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Tue, 22 Mar 2022 17:50:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Count-ONLY-if-2-named-services-happen-on-same-date/m-p/1908334#M74877</guid>
      <dc:creator>mbeccaria</dc:creator>
      <dc:date>2022-03-22T17:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: Count ONLY if 2 named services happen on same date</title>
      <link>https://community.qlik.com/t5/App-Development/Count-ONLY-if-2-named-services-happen-on-same-date/m-p/1908375#M74882</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Not sure about your exact field names, but how about something like;&lt;/P&gt;
&lt;P&gt;sum(aggr(if(count({&amp;lt;Service={'A','B'}&amp;gt;}Service)=2,1,0),Date,Client))&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Chris.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 19:51:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Count-ONLY-if-2-named-services-happen-on-same-date/m-p/1908375#M74882</guid>
      <dc:creator>chrismarlow</dc:creator>
      <dc:date>2022-03-22T19:51:21Z</dc:date>
    </item>
    <item>
      <title>Re: Count ONLY if 2 named services happen on same date</title>
      <link>https://community.qlik.com/t5/App-Development/Count-ONLY-if-2-named-services-happen-on-same-date/m-p/1908396#M74885</link>
      <description>&lt;P&gt;Expanding on that suggestion, I would suggest:&lt;/P&gt;
&lt;P&gt;Count(distinct (aggr(if(count(distinct {&amp;lt;Service={'A','B'}&amp;gt;}Service)=2,Client),Date,Client))&lt;/P&gt;
&lt;P&gt;Assuming I didn't mess up the logic (I can't syntax-check it), this has two advantages:&lt;/P&gt;
&lt;P&gt;1) It won't count instances where a client got service A or B twice in the same day, but not the other type. If that's not possible, the inner distinct isn't necessary.&lt;/P&gt;
&lt;P&gt;2) It will count the number of distinct clients meeting the criteria, not the number of dates where it happened. If I read the requirement correctly, that's the intent.&lt;/P&gt;
&lt;P&gt;If I did screw up the syntax, hopefully this is a nudge in the right direction.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2022 20:53:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Count-ONLY-if-2-named-services-happen-on-same-date/m-p/1908396#M74885</guid>
      <dc:creator>Or</dc:creator>
      <dc:date>2022-03-22T20:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: Count ONLY if 2 named services happen on same date</title>
      <link>https://community.qlik.com/t5/App-Development/Count-ONLY-if-2-named-services-happen-on-same-date/m-p/1908903#M74925</link>
      <description>&lt;P&gt;Pure gold. Thank you both!&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2022 16:06:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Count-ONLY-if-2-named-services-happen-on-same-date/m-p/1908903#M74925</guid>
      <dc:creator>mbeccaria</dc:creator>
      <dc:date>2022-03-23T16:06:03Z</dc:date>
    </item>
  </channel>
</rss>

