<?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-if with max function in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528027#M197317</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Yonatan,&lt;/P&gt;&lt;P&gt;My pleasure.&lt;/P&gt;&lt;P&gt;Kindly label response as 'correct answer', this helps other users to find the correct answer.&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 17 Nov 2013 09:41:21 GMT</pubDate>
    <dc:creator>mark_casselman</dc:creator>
    <dc:date>2013-11-17T09:41:21Z</dc:date>
    <item>
      <title>Count-if with max function</title>
      <link>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528018#M197308</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I have an issue that I hope that one of you already handle it already.&lt;/P&gt;&lt;P&gt;In my model I manage information on huge amount of parameters. each parameter has an ID called System_Key.&lt;/P&gt;&lt;P&gt;For each system key there are a lot of samples. each sample has a unique number per System_Key.&lt;/P&gt;&lt;P&gt;The numbers for the samples are being generated according the chronological order.&lt;/P&gt;&lt;P&gt;In one of my measurements I'd like to calculate for each System_Key only its last 30 samples.&lt;/P&gt;&lt;P&gt;After I didn't find any set analysis expression that might help, I decided to go to count-if...&lt;/P&gt;&lt;P&gt;Still, it didn't work out for so I started to try to isolate the problem, till I got to this:&lt;/P&gt;&lt;P&gt;supposed I'd like to count the number of samples which are bigger than the maximum sample number -30.&lt;/P&gt;&lt;P&gt;the expectation is that for each System_Key we'll get either 30 or less. The expression I had thought of is as the following:&lt;/P&gt;&lt;P&gt;=count(if(SampleNumber&amp;gt;=RangeMax(max(SampleNumber)-30,0),SampleNumber)).&lt;/P&gt;&lt;P&gt;But it doesn't work. as I went deeper with it, I understood that the QV doesn't allow to have count(max()) function.&lt;/P&gt;&lt;P&gt;So after this very long story, does anyone have any work around to it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot in advance for those of you that made till the end of the message &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;Hopefully one of you will be my rescuer!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Nov 2013 16:54:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528018#M197308</guid>
      <dc:creator />
      <dc:date>2013-11-14T16:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: Count-if with max function</title>
      <link>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528019#M197309</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried set analysis with your if statement? Maybe try like this:&lt;/P&gt;&lt;P&gt;=count({&amp;lt;SampleNumber = {'&amp;gt;$(=RangeMax(max(SampleNumber)-30,0))'}&amp;gt;}SampleNumber)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or maybe a variable:&lt;/P&gt;&lt;P&gt;=count({&amp;lt;SampleNumber = {'&amp;gt;$(vMax)'}&amp;gt;}SampleNumber)&lt;/P&gt;&lt;P&gt;with value of =RangeMax(max(SampleNumber)-30,0) for vMax&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Nov 2013 18:27:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528019#M197309</guid>
      <dc:creator>jerem1234</dc:creator>
      <dc:date>2013-11-14T18:27:13Z</dc:date>
    </item>
    <item>
      <title>Re: Count-if with max function</title>
      <link>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528020#M197310</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thank you for your replay!!&lt;/P&gt;&lt;P&gt;What you have suggested I've already tried.&lt;/P&gt;&lt;P&gt;The problem with it, is that I get the Max(SampleNumber) for all System_Key, and not for specific one.&lt;/P&gt;&lt;P&gt;For example, if I have System_Key with 100 samples , one with 80 and one with 50, for the 1st I'll get 30 for the 2nd I'll get 10 and for the 3rd 0.&lt;/P&gt;&lt;P&gt;So the solution has to be per System_Key (already try to put aggr(expression, System_Key), getting null for all System_Key).&lt;/P&gt;&lt;P&gt;Thanks a lot for the afford!! any other ideas?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Nov 2013 18:37:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528020#M197310</guid>
      <dc:creator />
      <dc:date>2013-11-14T18:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: Count-if with max function</title>
      <link>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528021#M197311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you need to be selection sensitive? That means, for a given System_Key, do the latest X samples change depending on selections?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If not, you can probably assign '1' to the latest sample for each System_Key, '2'&amp;nbsp; for the second latest etc.&lt;/P&gt;&lt;P&gt;using a sort desc and autonumber() [look into the two argument version] in your script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Creating a new field that index the samples on a timeline from now to back in history.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then simply filter your records like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;=count({&amp;lt;SampleNumberIndex = {"&amp;lt;=30"}&amp;gt;} SampleNumber)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Nov 2013 18:48:48 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528021#M197311</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2013-11-14T18:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: Count-if with max function</title>
      <link>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528022#M197312</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think it should work with AGGR. Also, if you upload a small sample app it'll be easier to help you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However you may try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Create a straight table with System_Key as dimension and the next expression:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AGGR (&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Count( { $&amp;lt; Sample_Number={ "&amp;gt;= $(=Max(Sample_Number)-30) " } &amp;gt; } DISTINCT Sample_Number)&lt;/P&gt;&lt;P&gt;,System_Key)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Nov 2013 18:49:31 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528022#M197312</guid>
      <dc:creator>Carlos_Reyes</dc:creator>
      <dc:date>2013-11-14T18:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: Count-if with max function</title>
      <link>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528023#M197313</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Maybe try this in a straight table with dimension System_Key and expression:&lt;/P&gt;&lt;P&gt;=if(aggr(max(SampleNumber),System_Key)&amp;gt;30, aggr(max(SampleNumber),System_Key) - 30, 0)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So if you have a 40 samples for a system, this will give you a value of 10. If you have 20 samples, this will give 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or you can try:&lt;/P&gt;&lt;P&gt;if(aggr(max(SampleNumber),System_Key)&amp;gt;30, aggr(max(SampleNumber),System_Key) - 30, aggr(max(SampleNumber),System_Key))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So if you have 40 samples for a system, this will give you a value of 10. If you have 20 samples, this will give 20.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not sure which you want. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Nov 2013 19:29:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528023#M197313</guid>
      <dc:creator>jerem1234</dc:creator>
      <dc:date>2013-11-14T19:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: Count-if with max function</title>
      <link>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528024#M197314</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yonatan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think I cracked it. After some trial and error if came up with this formula:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; color: #0000ff;"&gt;sum(aggr(&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: 'courier new', courier; font-size: 10pt; line-height: 1.5em;"&gt;if(SampleNumber &amp;gt; (max(total&amp;lt;System_Key&amp;gt; aggr(max(SampleNumber),System_Key))-30) , 1, 0 ),SampleNumber, System_K&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; font-family: 'courier new', courier; font-size: 10pt; line-height: 1.5em;"&gt;ey))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not sure that this is the most efficient/simple solution, but I tested it and it did the job.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some explaination&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-family: 'courier new', courier;"&gt;aggr(max(SampleNumber),System_Key)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;gives a highest samplenumber for every System_key&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-family: 'courier new', courier;"&gt;max(total&amp;lt;System_Key&amp;gt; aggr(max(SampleNumber),System_Key))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;gives this highest number back for every individual sample (try both formulas in a straight table and you will see the difference)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-family: 'courier new', courier;"&gt;if(SampleNumber &amp;gt; (max(total&amp;lt;System_Key&amp;gt; aggr(max(SampleNumber),System_Key))-30) , 1, 0 )&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;substract 30 and check every sample number is bigger or not. If bigger return 1 else return 0&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; color: #0000ff;"&gt;aggr(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: #0000ff; font-family: 'courier new', courier;"&gt;if(SampleNumber &amp;gt; (max(total&amp;lt;System_Key&amp;gt; aggr(max(SampleNumber),System_Key))-30) , 1, 0 ),SampleNumber, System_K&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: #0000ff; font-family: 'courier new', courier;"&gt;ey)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Do the previous for every samplenumber of every system_key&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; color: #0000ff;"&gt;sum(aggr(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: #0000ff; font-family: 'courier new', courier;"&gt;if(SampleNumber &amp;gt; (max(total&amp;lt;System_Key&amp;gt; aggr(max(SampleNumber),System_Key))-30) , 1, 0 ),SampleNumber, System_K&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; color: #0000ff; font-family: 'courier new', courier;"&gt;ey))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;And sum it !&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The result gives the total number of samples that exist and that are within the last 30.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It was quite a challenge !&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Nov 2013 23:09:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528024#M197314</guid>
      <dc:creator>mark_casselman</dc:creator>
      <dc:date>2013-11-14T23:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: Count-if with max function</title>
      <link>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528025#M197315</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;To answering your question, I do need it to be selection sensitive. Therefore putting constant number there won't work. Thank you for your effort!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Nov 2013 07:06:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528025#M197315</guid>
      <dc:creator />
      <dc:date>2013-11-17T07:06:23Z</dc:date>
    </item>
    <item>
      <title>Re: Count-if with max function</title>
      <link>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528026#M197316</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mark,&lt;/P&gt;&lt;P&gt;Thanks a lot!!! Works perfectly!! &lt;/P&gt;&lt;P&gt;Also, thanks for the detailed explanation!!!&lt;/P&gt;&lt;P&gt;Thank you all for all of your ideas and attempts - Much appreciated &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Nov 2013 07:12:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528026#M197316</guid>
      <dc:creator />
      <dc:date>2013-11-17T07:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: Count-if with max function</title>
      <link>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528027#M197317</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Yonatan,&lt;/P&gt;&lt;P&gt;My pleasure.&lt;/P&gt;&lt;P&gt;Kindly label response as 'correct answer', this helps other users to find the correct answer.&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Nov 2013 09:41:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Count-if-with-max-function/m-p/528027#M197317</guid>
      <dc:creator>mark_casselman</dc:creator>
      <dc:date>2013-11-17T09:41:21Z</dc:date>
    </item>
  </channel>
</rss>

