<?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 Help Newbie: need help with caluculation in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Help-Newbie-need-help-with-caluculation/m-p/222553#M75218</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have two values LastPayment and NextPayment -these are both dates with the form mm-dd-yy&lt;/P&gt;&lt;P&gt;I need to show the the % of loans where Diff LastPayment and NextPayment &amp;gt; 30 days.&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 19 Apr 2011 18:53:11 GMT</pubDate>
    <dc:creator />
    <dc:date>2011-04-19T18:53:11Z</dc:date>
    <item>
      <title>Help Newbie: need help with caluculation</title>
      <link>https://community.qlik.com/t5/QlikView/Help-Newbie-need-help-with-caluculation/m-p/222553#M75218</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have two values LastPayment and NextPayment -these are both dates with the form mm-dd-yy&lt;/P&gt;&lt;P&gt;I need to show the the % of loans where Diff LastPayment and NextPayment &amp;gt; 30 days.&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Apr 2011 18:53:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Help-Newbie-need-help-with-caluculation/m-p/222553#M75218</guid>
      <dc:creator />
      <dc:date>2011-04-19T18:53:11Z</dc:date>
    </item>
    <item>
      <title>Help Newbie: need help with caluculation</title>
      <link>https://community.qlik.com/t5/QlikView/Help-Newbie-need-help-with-caluculation/m-p/222554#M75219</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK. Part way there. This is what I have so far...&lt;/P&gt;&lt;P&gt;num(month([Next Payment Due])) - num(month([Last Payment Due]))&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Apr 2011 19:34:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Help-Newbie-need-help-with-caluculation/m-p/222554#M75219</guid>
      <dc:creator />
      <dc:date>2011-04-19T19:34:55Z</dc:date>
    </item>
    <item>
      <title>Help Newbie: need help with caluculation</title>
      <link>https://community.qlik.com/t5/QlikView/Help-Newbie-need-help-with-caluculation/m-p/222555#M75220</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;The way I would approach this would be to add some flags in the load script, this will make your expressions simpler in the front end.&lt;/P&gt;&lt;P&gt;Something like:&lt;/P&gt;&lt;P style="font-weight: bold"&gt;Loans:&lt;BR /&gt;LOAD&lt;BR /&gt; 1 as LoanCount,&lt;BR /&gt; if(NextPayment - LastPayment &amp;gt; 30, 1, 0) as Over30Count,&lt;BR /&gt; [... rest of table load ...]&lt;/P&gt;&lt;P&gt;Your expression is then simply:&lt;/P&gt;&lt;P style="font-weight: bold"&gt;SUM(Over30Count) / SUM(LoanCount)&lt;/P&gt;&lt;P&gt;Creating flags and count fields at load time substantially speeds up calculation times and also breaks up calculations into easier to manage chunks.&lt;/P&gt;&lt;P&gt;If you want to have a dynamic gap between the dates (perhaps on a slider) then you need to nest a if statement in the first sum, eg.:&lt;/P&gt;&lt;P style="font-weight: bold"&gt;SUM(if(NextPayment - LastPayment &amp;gt; $(vDaysDiff), LoanCount, 0)) / SUM(LoanCount)&lt;/P&gt;&lt;P&gt;Note that this still uses the '1 as LoanCount' in the load script.&lt;/P&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;Steve&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Apr 2011 19:59:29 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Help-Newbie-need-help-with-caluculation/m-p/222555#M75220</guid>
      <dc:creator>stevedark</dc:creator>
      <dc:date>2011-04-19T19:59:29Z</dc:date>
    </item>
    <item>
      <title>AW:Help Newbie: need help with caluculation</title>
      <link>https://community.qlik.com/t5/QlikView/Help-Newbie-need-help-with-caluculation/m-p/222556#M75221</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Calculate in your code, the difference between last and next payment and create thefield lastPay_30d&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;&lt;BR /&gt;if((NextPayment-LastPayment) &amp;gt;= 30, 'Y','N') as lastPay_30d&lt;BR /&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;Now you can create a ListBox from lastPay_30d. So can you sellect all your Customers with the Payment Difference.&lt;/P&gt;&lt;P&gt;&lt;A href="http://community.qlik.com/cfs-file.ashx/__key/CommunityServer.Discussions.Components.Files/11/0334.qlikjam_2D00_98.png"&gt;&lt;IMG alt="" border="0" src="http://community.qlik.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Discussions.Components.Files/11/0334.qlikjam_2D00_98.png" /&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The Payment difference you can make dynamic. You can do it with Set Analisys.&lt;/P&gt;&lt;P&gt;- QlikJam&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Apr 2011 20:00:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Help-Newbie-need-help-with-caluculation/m-p/222556#M75221</guid>
      <dc:creator />
      <dc:date>2011-04-19T20:00:21Z</dc:date>
    </item>
    <item>
      <title>AW:Help Newbie: need help with caluculation</title>
      <link>https://community.qlik.com/t5/QlikView/Help-Newbie-need-help-with-caluculation/m-p/222557#M75222</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Rather than 1/0 or Y/N flags (though use Y/N if you want it to be selectable), I'd use a 1/null flag, which I think would make for a more efficient sum.&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;if(NextPayment - LastPayment &amp;gt; 30,1) as Over30Count&lt;/P&gt;&lt;P&gt;If your percentage is supposed to be by LoanAmount instead of by count, you could do this:&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;sum({&amp;lt;Over30Count={1}&amp;gt;} LoanAmount)/sum(LoanAmount)&lt;/P&gt;&lt;P&gt;Or this:&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;if(NextPayment - LastPayment &amp;gt; 30,LoanAmount) as Over30Amount&lt;/P&gt;&lt;P style="padding-left:30px;"&gt;sum(Over30Amount)/sum(LoanAmount)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Apr 2011 23:53:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Help-Newbie-need-help-with-caluculation/m-p/222557#M75222</guid>
      <dc:creator>johnw</dc:creator>
      <dc:date>2011-04-19T23:53:09Z</dc:date>
    </item>
    <item>
      <title>AW:Help Newbie: need help with caluculation</title>
      <link>https://community.qlik.com/t5/QlikView/Help-Newbie-need-help-with-caluculation/m-p/222558#M75223</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi John,&lt;/P&gt;&lt;P&gt;I tend to make a point of avoiding nulls where possible. On one site I had a client with 200 million rows in their document and replacing nulls with zeros made a huge difference to some of the calculations - I can not recall if the value in question was used in set analysis or the standard part of the expression. Needs some benchmarking to be sure.&lt;/P&gt;&lt;P&gt;The other reason I like the binary flag is that it can then be used in expressions - which I find useful with clients that have an aversion to section access, eg.:&lt;/P&gt;&lt;P style="font-weight: bold"&gt;sum(LoanAmount * Over30Count) / sum(LoanAmount)&lt;/P&gt;&lt;P&gt;My guess is that the above statement would perform slower than the set analysis version - but it is readable by someone with a phobia of curly brackets.&lt;/P&gt;&lt;P&gt;Regarding your point on being selectable, I sometimes have fields both ways - as we know that a field with only two values in takes virtually no memory even when on a massive table. This I tend to do with a preceding load:&lt;/P&gt;&lt;P style="font-weight: bold"&gt;LOAD&lt;BR /&gt; *,&lt;BR /&gt; ApplyMap('Map_Bool2YesNo', Over30Count) as [Is Over 30]&lt;BR /&gt; ;&lt;BR /&gt;LOAD&lt;BR /&gt; [...]&lt;/P&gt;&lt;P&gt;I completely agree with your suggestion about adding an Over30Amount field into the data model - certainly the best way to make calculations on that more efficient. Again I tend to calculate the boolean in the main body of the load and then use this in a preceding load to create extra fields, eg.:&lt;/P&gt;&lt;P style="font-weight: bold"&gt;LOAD&lt;BR /&gt; *,&lt;BR /&gt; LoanAmount * Over30Count as Over30Amount&lt;/P&gt;&lt;P&gt;Many thanks for sharing your thoughts, John, always good to get ideas from an expert!&lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;Steve&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Apr 2011 07:40:01 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Help-Newbie-need-help-with-caluculation/m-p/222558#M75223</guid>
      <dc:creator>stevedark</dc:creator>
      <dc:date>2011-04-20T07:40:01Z</dc:date>
    </item>
  </channel>
</rss>

