<?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 Max date set analysis doesn't work. in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Max-date-set-analysis-doesn-t-work/m-p/227331#M79442</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hey guys, first of all, I want to tell that I've been trying all the post refering "max date set analysis", but it doesn't work for me, and I don't know why.&lt;/P&gt;&lt;P&gt;Here I have a pivot table that shows the Medical History of a patient, the ID Episode (a patient has 1 Medical History but could have N Episodes), the date of the ending of the episode, and the number of treatment the patient receives.&lt;/P&gt;&lt;P&gt;&lt;IMG alt="error loading image" class="jive-image error-loading-image" src="https://community.qlik.com/legacyfs/online/-2510_sourceID:2510" /&gt;&lt;/P&gt;&lt;P&gt;By now, if I want to calculate the treatments of the Medical History 10267, the result would be 17 + 21 = 38. And my desired result is 21 (the last one).&lt;/P&gt;&lt;P&gt;Moreover, I need to consider that the last episode could not be finished, so the date is null, and I need to take the last finished episode.&lt;/P&gt;&lt;P&gt;For example, the Medical History 10999 has 2 episodes, one finished and the other not, if I count it now, the result would be 22 + 23 = 45. And my desired result is 22, because is the number of treatments of the last finished episode.&lt;/P&gt;&lt;P&gt;Here's my expression to calculate the number of treatments, what I'm doing is to filter by some kind of pacient benefits "UsuariPrestacio", and the date values between my selected dates of the application :&lt;/P&gt;&lt;P&gt;&lt;B&gt;=count({$&amp;lt; UsuariPrestacio = {'CPL', 'CNV' ,'ME PSICO', 'LLE'} &amp;gt;} distinct&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;IF( (DataAltaNum &amp;gt;= vEstadaMinData AND DataAltaNum &amp;lt;= vEstadaMaxData) OR&lt;/B&gt;&lt;/P&gt;&lt;P style="font-weight: bold"&gt;(DataIngresNum &amp;lt;= vEstadaMaxData AND (DataAltaNum = 0 OR DataAltaNum &amp;gt; vEstadaMaxData)), IDTractament ))&lt;/P&gt;&lt;P&gt;What I've added to fix it is the max(date), in this case "DataAltaNum" of the last episode, but it doesn't work. I do exactly this :&lt;/P&gt;&lt;P&gt;&lt;B&gt;=count({$&amp;lt; UsuariPrestacio = {'CPL', 'CNV' ,'ME PSICO', 'LLE'} , &lt;I&gt;DataAltaNum = {'$(=Max(DataAltaNum))'}&lt;/I&gt;&lt;/B&gt; &amp;gt;} distinct&lt;/P&gt;&lt;P&gt;&lt;B&gt;IF( (DataAltaNum &amp;gt;= vEstadaMinData AND DataAltaNum &amp;lt;= vEstadaMaxData) OR&lt;/B&gt;&lt;/P&gt;&lt;P style="font-weight: bold"&gt;(DataIngresNum &amp;lt;= vEstadaMaxData AND (DataAltaNum = 0 OR DataAltaNum &amp;gt; vEstadaMaxData)), IDTractament ))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anybody knows what I'm doing wrong?&lt;/P&gt;&lt;P&gt;Any clue would be appreciated.&lt;/P&gt;&lt;P&gt;Many thanks by advance!!!&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 04 Oct 2010 16:50:14 GMT</pubDate>
    <dc:creator>marcel_olmo</dc:creator>
    <dc:date>2010-10-04T16:50:14Z</dc:date>
    <item>
      <title>Max date set analysis doesn't work.</title>
      <link>https://community.qlik.com/t5/QlikView/Max-date-set-analysis-doesn-t-work/m-p/227331#M79442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hey guys, first of all, I want to tell that I've been trying all the post refering "max date set analysis", but it doesn't work for me, and I don't know why.&lt;/P&gt;&lt;P&gt;Here I have a pivot table that shows the Medical History of a patient, the ID Episode (a patient has 1 Medical History but could have N Episodes), the date of the ending of the episode, and the number of treatment the patient receives.&lt;/P&gt;&lt;P&gt;&lt;IMG alt="error loading image" class="jive-image error-loading-image" src="https://community.qlik.com/legacyfs/online/-2510_sourceID:2510" /&gt;&lt;/P&gt;&lt;P&gt;By now, if I want to calculate the treatments of the Medical History 10267, the result would be 17 + 21 = 38. And my desired result is 21 (the last one).&lt;/P&gt;&lt;P&gt;Moreover, I need to consider that the last episode could not be finished, so the date is null, and I need to take the last finished episode.&lt;/P&gt;&lt;P&gt;For example, the Medical History 10999 has 2 episodes, one finished and the other not, if I count it now, the result would be 22 + 23 = 45. And my desired result is 22, because is the number of treatments of the last finished episode.&lt;/P&gt;&lt;P&gt;Here's my expression to calculate the number of treatments, what I'm doing is to filter by some kind of pacient benefits "UsuariPrestacio", and the date values between my selected dates of the application :&lt;/P&gt;&lt;P&gt;&lt;B&gt;=count({$&amp;lt; UsuariPrestacio = {'CPL', 'CNV' ,'ME PSICO', 'LLE'} &amp;gt;} distinct&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;IF( (DataAltaNum &amp;gt;= vEstadaMinData AND DataAltaNum &amp;lt;= vEstadaMaxData) OR&lt;/B&gt;&lt;/P&gt;&lt;P style="font-weight: bold"&gt;(DataIngresNum &amp;lt;= vEstadaMaxData AND (DataAltaNum = 0 OR DataAltaNum &amp;gt; vEstadaMaxData)), IDTractament ))&lt;/P&gt;&lt;P&gt;What I've added to fix it is the max(date), in this case "DataAltaNum" of the last episode, but it doesn't work. I do exactly this :&lt;/P&gt;&lt;P&gt;&lt;B&gt;=count({$&amp;lt; UsuariPrestacio = {'CPL', 'CNV' ,'ME PSICO', 'LLE'} , &lt;I&gt;DataAltaNum = {'$(=Max(DataAltaNum))'}&lt;/I&gt;&lt;/B&gt; &amp;gt;} distinct&lt;/P&gt;&lt;P&gt;&lt;B&gt;IF( (DataAltaNum &amp;gt;= vEstadaMinData AND DataAltaNum &amp;lt;= vEstadaMaxData) OR&lt;/B&gt;&lt;/P&gt;&lt;P style="font-weight: bold"&gt;(DataIngresNum &amp;lt;= vEstadaMaxData AND (DataAltaNum = 0 OR DataAltaNum &amp;gt; vEstadaMaxData)), IDTractament ))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anybody knows what I'm doing wrong?&lt;/P&gt;&lt;P&gt;Any clue would be appreciated.&lt;/P&gt;&lt;P&gt;Many thanks by advance!!!&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Oct 2010 16:50:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Max-date-set-analysis-doesn-t-work/m-p/227331#M79442</guid>
      <dc:creator>marcel_olmo</dc:creator>
      <dc:date>2010-10-04T16:50:14Z</dc:date>
    </item>
    <item>
      <title>Max date set analysis doesn't work.</title>
      <link>https://community.qlik.com/t5/QlikView/Max-date-set-analysis-doesn-t-work/m-p/227332#M79443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When you use Max(DataAltaNum) inside a dollar sign expansion in your final expression, it is not evaluating the Max for that record, but the Max for your entire data set.&lt;/P&gt;&lt;P&gt;I think you would need something like:&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;=count({$&amp;lt; UsuariPrestacio = {'CPL', 'CNV' ,'ME PSICO', 'LLE'} ,&lt;BR /&gt;DataAltaNum = {'$(=Aggr(Max(DataAltaNum)), MedicalHistory, Episode)'} &amp;gt;} distinct ...&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;Dollar Sign Expansions are evaluated for the entire data set. They are not evaluated record by record, which is probably why they are so fast. This will get the Max for every combination on MedicalHistory &amp;amp; Episode (guessed at those field names), which seems to be what you are going for.&lt;/P&gt;&lt;P&gt;EDIT: It looks like I was confused. I don't think the Aggr works in the dollar sign expansion like this. You may need to add this clause in an if statement, rather than Set Analysis.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Oct 2010 17:03:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Max-date-set-analysis-doesn-t-work/m-p/227332#M79443</guid>
      <dc:creator />
      <dc:date>2010-10-04T17:03:35Z</dc:date>
    </item>
    <item>
      <title>Max date set analysis doesn't work.</title>
      <link>https://community.qlik.com/t5/QlikView/Max-date-set-analysis-doesn-t-work/m-p/227333#M79444</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much NMiller to answer me so quickly.&lt;/P&gt;&lt;P&gt;I'm afraid your solution still doesn't work for me. I did it as you wrote (changing the name of the variables for the real ones), but it doesn't work.&lt;/P&gt;&lt;P&gt;Is there any other possibility?&lt;/P&gt;&lt;P&gt;Thanks anyway!!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Oct 2010 17:55:10 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Max-date-set-analysis-doesn-t-work/m-p/227333#M79444</guid>
      <dc:creator>marcel_olmo</dc:creator>
      <dc:date>2010-10-04T17:55:10Z</dc:date>
    </item>
    <item>
      <title>Max date set analysis doesn't work.</title>
      <link>https://community.qlik.com/t5/QlikView/Max-date-set-analysis-doesn-t-work/m-p/227334#M79445</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try something like this (ifs instead of Set Analysis):&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;=count({$&amp;lt; UsuariPrestacio = {'CPL', 'CNV' ,'ME PSICO', 'LLE'} distinct&lt;BR /&gt;IF( (DataAltaNum &amp;gt;= vEstadaMinData AND DataAltaNum &amp;lt;= vEstadaMaxData) OR&lt;BR /&gt;(DataIngresNum &amp;lt;= vEstadaMaxData AND (DataAltaNum = 0 OR DataAltaNum &amp;gt; vEstadaMaxData))&lt;BR /&gt;AND DataAltaNum = Max(TOTAL &amp;lt;MedicalHistory, Episode&amp;gt; DataAltaNum), IDTractament ))&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;That should require one of your original ifs to be true and require that the DataAltaNum field match the Maximum DatAltaNum per MedicalHistory and Episode combination.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Oct 2010 19:42:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Max-date-set-analysis-doesn-t-work/m-p/227334#M79445</guid>
      <dc:creator />
      <dc:date>2010-10-04T19:42:21Z</dc:date>
    </item>
    <item>
      <title>Max date set analysis doesn't work.</title>
      <link>https://community.qlik.com/t5/QlikView/Max-date-set-analysis-doesn-t-work/m-p/227335#M79446</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you NMiller again. You gettin very closer. But the point is that you inspire me to get the right solution.&lt;/P&gt;&lt;P&gt;This is what I get, more or less is my desired result, and a valid solution :&lt;/P&gt;&lt;P&gt;&lt;A href="http://community.qlik.com/cfs-file.ashx/__key/CommunityServer.Discussions.Components.Files/11/6558.ok.JPG"&gt;&lt;IMG alt="" border="0" src="http://community.qlik.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Discussions.Components.Files/11/6558.ok.JPG" /&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've realized that I cannot get the max value of a date, it has to be a number. so to calculate the "Max Number date" I do as a expression :&lt;/P&gt;&lt;P style="font-weight: bold"&gt;Max Number date : Max(TOTAL &amp;lt;HC&amp;gt; DataAltaNum)&lt;/P&gt;&lt;P&gt;And to calculate the Number of treatments of the last episode, I check with an IF, if it's the last date of the episode, I put the counter of episodes, otherwise, I put a 0, so when I make the sum of all the values, everything is gonna be well calculated.&lt;/P&gt;&lt;P&gt;This is my solution :&lt;/P&gt;&lt;P style="font-weight: bold"&gt;Nº of treatments : = if ( DataAltaNum = Max(TOTAL &amp;lt;HC&amp;gt; DataAltaNum),&lt;BR /&gt;&lt;BR /&gt; count({$&amp;lt; UsuariPrestacio = {'CPL', 'CNV' ,'ME PSICO', 'LLE'} &amp;gt;}&lt;BR /&gt;&lt;BR /&gt; distinct IF( ( (DataAltaNum &amp;gt;= vEstadaMinData AND DataAltaNum &amp;lt;= vEstadaMaxData) OR&lt;BR /&gt;&lt;BR /&gt; (DataIngresNum &amp;lt;= vEstadaMaxData AND (DataAltaNum = 0 OR DataAltaNum &amp;gt; vEstadaMaxData)) ) , IDTractament )),0 )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks NMiller for helping me.&lt;/P&gt;&lt;P&gt;See you around!&lt;/P&gt;&lt;P&gt;Regards.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Oct 2010 15:38:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Max-date-set-analysis-doesn-t-work/m-p/227335#M79446</guid>
      <dc:creator>marcel_olmo</dc:creator>
      <dc:date>2010-10-05T15:38:59Z</dc:date>
    </item>
  </channel>
</rss>

