<?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 Problem: Expression generating negative numbers in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Problem-Expression-generating-negative-numbers/m-p/339581#M1171562</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Christopher, Thank you very much for that! It's so simple when I look at it. It nailed the spot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Take care.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Paul.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 06 Jun 2012 10:01:44 GMT</pubDate>
    <dc:creator />
    <dc:date>2012-06-06T10:01:44Z</dc:date>
    <item>
      <title>Problem: Expression generating negative numbers</title>
      <link>https://community.qlik.com/t5/QlikView/Problem-Expression-generating-negative-numbers/m-p/339579#M1171560</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good Morning, I have a problem where I am trying to extract meter readings from our system. This example is an approximation of the data generating the problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;READ&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATE&lt;/P&gt;&lt;P&gt;297&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01.04.2012&lt;/P&gt;&lt;P&gt;9998&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01.03.2012&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The true difference between the two figures is -9701. However the true system difference is 299, the meter rolls back to 0 when it goes past 9999. Our system calculates this automatically but im unable extract this as its a calculated table (or structure)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using this Expression at the moment (which is giving the erroneous data) :- FirstSortedValue(Meter_Reading,-Meter_Reading_Date)-FirstSortedValue(Meter_Reading,-Meter_Reading_Date,3)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Paul. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Jun 2012 09:06:14 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Problem-Expression-generating-negative-numbers/m-p/339579#M1171560</guid>
      <dc:creator />
      <dc:date>2012-06-06T09:06:14Z</dc:date>
    </item>
    <item>
      <title>Problem: Expression generating negative numbers</title>
      <link>https://community.qlik.com/t5/QlikView/Problem-Expression-generating-negative-numbers/m-p/339580#M1171561</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;And if you try :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #636363; font-family: Arial; font-size: 12px; background-color: #eef4f9;"&gt;fabs(FirstSortedValue(Meter_Reading,-Meter_Reading_Date)-&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #636363; font-family: Arial; font-size: 12px; background-color: #eef4f9;"&gt;(FirstSortedValue(Meter_Reading,-Meter_Reading_Date,3)-9999))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #636363; font-family: Arial; font-size: 12px; background-color: #eef4f9;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Jun 2012 09:29:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Problem-Expression-generating-negative-numbers/m-p/339580#M1171561</guid>
      <dc:creator>christophebrault</dc:creator>
      <dc:date>2012-06-06T09:29:17Z</dc:date>
    </item>
    <item>
      <title>Problem: Expression generating negative numbers</title>
      <link>https://community.qlik.com/t5/QlikView/Problem-Expression-generating-negative-numbers/m-p/339581#M1171562</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Christopher, Thank you very much for that! It's so simple when I look at it. It nailed the spot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Take care.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Paul.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Jun 2012 10:01:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Problem-Expression-generating-negative-numbers/m-p/339581#M1171562</guid>
      <dc:creator />
      <dc:date>2012-06-06T10:01:44Z</dc:date>
    </item>
    <item>
      <title>Problem: Expression generating negative numbers</title>
      <link>https://community.qlik.com/t5/QlikView/Problem-Expression-generating-negative-numbers/m-p/339582#M1171563</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; One minor problem I have, this works well when negative numbers when a number starts before and including 9999 and then rolls over to 0+, the problem is when the number moves from 350 to 375 for example, I need the formula in the expression to deal with both, any ideas please? &lt;IMG src="https://community.qlik.com/legacyfs/online/emoticons/confused.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Jun 2012 14:56:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Problem-Expression-generating-negative-numbers/m-p/339582#M1171563</guid>
      <dc:creator />
      <dc:date>2012-06-06T14:56:40Z</dc:date>
    </item>
    <item>
      <title>Problem: Expression generating negative numbers</title>
      <link>https://community.qlik.com/t5/QlikView/Problem-Expression-generating-negative-numbers/m-p/339583#M1171564</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; ive tried :- &lt;/P&gt;&lt;P&gt;if(FirstSortedValue(Meter_Reading,-Meter_Reading_Date)-FirstSortedValue(Meter_Reading,-Meter_Reading_Date,3)&amp;lt;'0',&lt;/P&gt;&lt;P&gt;fabs(FirstSortedValue(Meter_Reading,-Meter_Reading_Date)-&lt;/P&gt;&lt;P&gt;FirstSortedValue(Meter_Reading,-Meter_Reading_Date,3)-9999)) which helps for the neg numbers, I need help to get this expression to deal with positive numbers 0 and greater to be calculated in same expression.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Jun 2012 15:10:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Problem-Expression-generating-negative-numbers/m-p/339583#M1171564</guid>
      <dc:creator />
      <dc:date>2012-06-06T15:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: Problem: Expression generating negative numbers</title>
      <link>https://community.qlik.com/t5/QlikView/Problem-Expression-generating-negative-numbers/m-p/339584#M1171567</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, I think you can just reuse your original expression for the 'standard case', can't you?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or create a aggregated READ value in the script like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;LOAD *&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;, rangesum(if(READ&amp;lt;peek(READ),10000),peek(AggrREAD),READ-peek(READ)) as AggrREAD &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;INLINE&amp;nbsp; [&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;READ,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATE&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;9998,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01.03.2012&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;297,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01.04.2012&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;350,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01.05.2012&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;8000,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01.01.2014&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;100,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01.01.2015&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;2222,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01.02.2016&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;0,&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 01.03.2020&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;];&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So you don't need to bother about crossing the 9999 border anymore after.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Stefan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;edit: this needs an ordered table to work correctly, and if you want to start with your first READ value and not zero as AggrREAD, you could use:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;LOAD *, &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;if(isnull(peek(READ)), READ,&lt;/STRONG&gt;rangesum(if(READ&amp;lt;peek(READ),10000),peek(AggrREAD),READ-peek(READ))) as AggrREAD &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;INLINE&amp;nbsp; [&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;...&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Jun 2012 15:46:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Problem-Expression-generating-negative-numbers/m-p/339584#M1171567</guid>
      <dc:creator>swuehl</dc:creator>
      <dc:date>2012-06-06T15:46:17Z</dc:date>
    </item>
  </channel>
</rss>

