<?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 Knock Off the Negative Value .... in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Knock-Off-the-Negative-Value/m-p/210374#M64975</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi valera,&lt;/P&gt;&lt;P&gt;Thanks for the logic but there is a small problem in this.&lt;/P&gt;&lt;P&gt;If you the change the -70 to -20 in the data you will not get the correct output..&lt;/P&gt;&lt;P&gt;A 01.02.2010 100&lt;/P&gt;&lt;P&gt;A 05.02.2010 40&lt;/P&gt;&lt;P&gt;A 10.02.2010 10&lt;/P&gt;&lt;P&gt;Let me know if your view on this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Deepak&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 12 Apr 2010 10:58:51 GMT</pubDate>
    <dc:creator>deepakk</dc:creator>
    <dc:date>2010-04-12T10:58:51Z</dc:date>
    <item>
      <title>Knock Off the Negative Value ....</title>
      <link>https://community.qlik.com/t5/QlikView/Knock-Off-the-Negative-Value/m-p/210372#M64973</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to Knock off the Postive value with respect to Negative Value .. eg :&lt;/P&gt;&lt;P&gt;Product Date Amount&lt;/P&gt;&lt;P&gt;A 01/02/2010 100&lt;/P&gt;&lt;P&gt;A 05/02/2010 60&lt;/P&gt;&lt;P&gt;A 07/02/2010 -70&lt;/P&gt;&lt;P&gt;A 10/02/2010 100&lt;/P&gt;&lt;P&gt;A 20/02/2010 -90&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;P&gt;Product Date Amount&lt;/P&gt;&lt;P&gt;A 01/02/2010 90&lt;/P&gt;&lt;P&gt;A 10/02/2010 10&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The -70 knock of the above 60 value and 10 value from 100 hence we have A on 01/02/2010 as 90.&lt;/P&gt;&lt;P&gt;and -90 knocked off 100 and the remaiing value is 10&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me know how we can achieve this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Deepak&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 11 Apr 2010 12:50:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Knock-Off-the-Negative-Value/m-p/210372#M64973</guid>
      <dc:creator>deepakk</dc:creator>
      <dc:date>2010-04-11T12:50:28Z</dc:date>
    </item>
    <item>
      <title>Knock Off the Negative Value ....</title>
      <link>https://community.qlik.com/t5/QlikView/Knock-Off-the-Negative-Value/m-p/210373#M64974</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Deepak,&lt;/P&gt;&lt;P&gt;a couple of weeks ago I faced a similar problem. So, I adopted my solution to your case. I just grouped the records by assigning a number to them.&lt;/P&gt;&lt;P&gt;The script can be enhanced to take group the days within a month and not within the whole time period.&lt;/P&gt;&lt;P&gt;Check out the script:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-weight: bold"&gt;&lt;/P&gt;&lt;P style="font-weight: bold"&gt;//get data&lt;/P&gt;&lt;P style="font-weight: bold"&gt;Data:&lt;/P&gt;&lt;P style="font-weight: bold"&gt;LOAD * INLINE [&lt;/P&gt;&lt;P style="font-weight: bold"&gt;Product, Date, Amount&lt;/P&gt;&lt;P style="font-weight: bold"&gt;A, 01.02.2010, 100&lt;/P&gt;&lt;P style="font-weight: bold"&gt;A, 05.02.2010, 60&lt;/P&gt;&lt;P style="font-weight: bold"&gt;A, 07.02.2010, -70&lt;/P&gt;&lt;P style="font-weight: bold"&gt;A, 10.02.2010, 100&lt;/P&gt;&lt;P style="font-weight: bold"&gt;A, 20.02.2010, -90&lt;/P&gt;&lt;P style="font-weight: bold"&gt;];&lt;/P&gt;&lt;P style="font-weight: bold"&gt;&lt;/P&gt;&lt;P style="font-weight: bold"&gt;//create record groups column&lt;/P&gt;&lt;P style="font-weight: bold"&gt;Temp1:&lt;/P&gt;&lt;P style="font-weight: bold"&gt;load&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;/B&gt;Product as Prod1&lt;/P&gt;&lt;P&gt;,Date as Date1&lt;/P&gt;&lt;P&gt;,Amount as Amount1&lt;/P&gt;&lt;P&gt;,if(peek(Amount1)&amp;lt;0,&lt;/P&gt;&lt;P&gt;peek(RecordGroup1) + 1&lt;/P&gt;&lt;P&gt;,&lt;/P&gt;&lt;P&gt;if(isnull(peek(Amount1)),&lt;/P&gt;&lt;P&gt;1,&lt;/P&gt;&lt;P&gt;peek(RecordGroup1)&lt;/P&gt;&lt;P&gt;)&lt;/P&gt;&lt;P&gt;) as RecordGroup1&lt;/P&gt;&lt;P&gt;resident Data&lt;/P&gt;&lt;P&gt;order by Product,Date;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//sum amount by recgroups&lt;/P&gt;&lt;P&gt;Temp2:&lt;/P&gt;&lt;P&gt;load&lt;/P&gt;&lt;P&gt;Prod1 as Prod2&lt;/P&gt;&lt;P&gt;,RecordGroup1 as RecordGroup2&lt;/P&gt;&lt;P&gt;,sum(Amount1) as Amount2&lt;/P&gt;&lt;P&gt;resident Temp1&lt;/P&gt;&lt;P&gt;group by &lt;B&gt;&lt;/B&gt;&lt;/P&gt;&lt;P style="font-weight: bold"&gt;&lt;/P&gt;&lt;B&gt;&lt;/B&gt;&lt;P style="font-weight: bold"&gt;Prod1,&lt;/P&gt;&lt;P style="font-weight: bold"&gt;RecordGroup1;&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;P&gt;//join temp1 and temp2 with min(Date)&lt;/P&gt;&lt;P&gt;Final:&lt;/P&gt;&lt;P&gt;load&lt;/P&gt;&lt;P&gt;Prod2 as Prod3&lt;/P&gt;&lt;P&gt;,RecordGroup2 as RecordGroup3&lt;/P&gt;&lt;P&gt;,Amount2 as Amount3&lt;/P&gt;&lt;P&gt;resident Temp2;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;inner join&lt;/P&gt;&lt;P&gt;load&lt;/P&gt;&lt;P&gt;Prod1 as Prod3&lt;/P&gt;&lt;P&gt;,min(Date1) as Date3&lt;/P&gt;&lt;P&gt;,RecordGroup1 as RecordGroup3&lt;/P&gt;&lt;P&gt;resident Temp1&lt;/P&gt;&lt;P&gt;group by Prod1,RecordGroup1;&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 11 Apr 2010 14:32:19 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Knock-Off-the-Negative-Value/m-p/210373#M64974</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-04-11T14:32:19Z</dc:date>
    </item>
    <item>
      <title>Knock Off the Negative Value ....</title>
      <link>https://community.qlik.com/t5/QlikView/Knock-Off-the-Negative-Value/m-p/210374#M64975</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi valera,&lt;/P&gt;&lt;P&gt;Thanks for the logic but there is a small problem in this.&lt;/P&gt;&lt;P&gt;If you the change the -70 to -20 in the data you will not get the correct output..&lt;/P&gt;&lt;P&gt;A 01.02.2010 100&lt;/P&gt;&lt;P&gt;A 05.02.2010 40&lt;/P&gt;&lt;P&gt;A 10.02.2010 10&lt;/P&gt;&lt;P&gt;Let me know if your view on this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Deepak&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Apr 2010 10:58:51 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Knock-Off-the-Negative-Value/m-p/210374#M64975</guid>
      <dc:creator>deepakk</dc:creator>
      <dc:date>2010-04-12T10:58:51Z</dc:date>
    </item>
    <item>
      <title>Knock Off the Negative Value ....</title>
      <link>https://community.qlik.com/t5/QlikView/Knock-Off-the-Negative-Value/m-p/210375#M64976</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Deepak,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess I did not understand well the problem. The current implementation creates the groups of records, the group end is reached when a record with a negative number is met. So, after this record a new group starts. Finally, all the records inside the groups are summed.&lt;/P&gt;&lt;P&gt;You are saying the logic is different. Could you explain? I'll see what is possible to do.&lt;/P&gt;&lt;P&gt;Valera &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Apr 2010 11:08:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Knock-Off-the-Negative-Value/m-p/210375#M64976</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-04-12T11:08:25Z</dc:date>
    </item>
    <item>
      <title>Knock Off the Negative Value ....</title>
      <link>https://community.qlik.com/t5/QlikView/Knock-Off-the-Negative-Value/m-p/210376#M64977</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi valera,&lt;/P&gt;&lt;P&gt;The logic is little different. we need to knock off the negative value with the last positive value. and finally we need to display the Product,date and the remaing positive value.&lt;/P&gt;&lt;P&gt;eg: Suppos in our same case we have&lt;/P&gt;&lt;P&gt;A, 01.02.2010, 100&lt;/P&gt;&lt;P&gt;A, 05.02.2010, 60&lt;/P&gt;&lt;P&gt;A, 07.02.2010, -40&lt;/P&gt;&lt;P&gt;A, 10.02.2010, 100&lt;/P&gt;&lt;P&gt;A, 20.02.2010, -90&lt;/P&gt;&lt;P&gt;Then the ouput should be&lt;/P&gt;&lt;P&gt;A, 01.02.2010, 100&lt;/P&gt;&lt;P&gt;A, 05.02.2010, 20 (-40 knocked off 60 and the remining 20 we need to display)&lt;/P&gt;&lt;P&gt;A, 10.02.2010, 10 (-90 knocked off 100 and the remining 10 we need to display)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ANOTHER EXAMPLE :&lt;/P&gt;&lt;P&gt;A, 01.02.2010, 100&lt;/P&gt;&lt;P&gt;A, 05.02.2010, 60&lt;/P&gt;&lt;P&gt;A, 07.02.2010, -80&lt;/P&gt;&lt;P&gt;A, 07.02.2010, -30&lt;/P&gt;&lt;P&gt;A, 10.02.2010, 100&lt;/P&gt;&lt;P&gt;A, 20.02.2010, -90&lt;/P&gt;&lt;P&gt;THEN THE OUTPUT SHOULD BE&lt;/P&gt;&lt;P&gt;A, 01.02.2010, 50 ( -80 KNOCKED OFF 60 AND WE HAVE BALANCE -20. ( -20+ -30= -50) WHICH KNOCK OFF THE 100 AND WE HAVE 50 REMAINING)&lt;/P&gt;&lt;P&gt;A, 10.02.2010, 10&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ITS LITTLE TRICKY BUT PLEASE LET ME KNOW IF YOU HAVE ANY QUERY ON THIS.&lt;/P&gt;&lt;P&gt;DEEPAK&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Apr 2010 11:20:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Knock-Off-the-Negative-Value/m-p/210376#M64977</guid>
      <dc:creator>deepakk</dc:creator>
      <dc:date>2010-04-12T11:20:53Z</dc:date>
    </item>
    <item>
      <title>Knock Off the Negative Value ....</title>
      <link>https://community.qlik.com/t5/QlikView/Knock-Off-the-Negative-Value/m-p/210377#M64978</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Deepak,&lt;/P&gt;&lt;P&gt;I guess I found a solution for your problem.&lt;/P&gt;&lt;P&gt;I adopted the algorithm of "sinking" the negative values until they "dissolve". So, what I actually did was:&lt;/P&gt;&lt;P&gt;1) sorting the table by product asc, date desc&lt;/P&gt;&lt;P&gt;2) in the load script checking the previous newly generated column with the sum of amounts&lt;/P&gt;&lt;P&gt;- if the previous newly generated amount is negative, then sum with current amount&lt;/P&gt;&lt;P&gt;- otherwise, put the current amount.&lt;/P&gt;&lt;P&gt;These steps produce a temp table where I all the positive newly generated amounts are the values that you need. So, here I create the Final table with the positive values from the temp table.&lt;/P&gt;&lt;P&gt;What remains is how to get the negative values (if the total sum of the amount for a product is negative).&lt;/P&gt;&lt;P&gt;3) create a temporary table with total amounts&lt;/P&gt;&lt;P&gt;4) filter a table from the step 2) to leave only the absolute negative values&lt;/P&gt;&lt;P&gt;5) add these negative values to the Final table&lt;/P&gt;&lt;P&gt;The resulting script is the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-weight: bold"&gt;qualify *;&lt;/P&gt;&lt;P&gt;&lt;B&gt;//get data&lt;BR /&gt;Data:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt; Product, Date, Amount&lt;BR /&gt; A, 01.02.2010, 100&lt;BR /&gt; A, 02.02.2010, 60&lt;BR /&gt; A, 03.02.2010, -20&lt;BR /&gt; A, 04.02.2010, 100&lt;BR /&gt; A, 05.02.2010, 60&lt;BR /&gt; A, 06.02.2010, -90&lt;BR /&gt; A, 07.02.2010, 100&lt;BR /&gt; A, 08.02.2010, -40&lt;BR /&gt; A, 09.02.2010, -70&lt;BR /&gt; B, 09.02.2010, 10&lt;BR /&gt; B, 10.02.2010, -70&lt;BR /&gt; ];&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;//sink negative values until they disappear&lt;BR /&gt;Temp:&lt;BR /&gt;load&lt;BR /&gt; Data.Product as Product&lt;BR /&gt; ,Data.Date as Date&lt;BR /&gt; ,Data.Amount as Amount&lt;BR /&gt; ,if(peek('Temp.Product') = Data.Product,&lt;BR /&gt; if(peek('Temp.Results') &amp;lt; 0,&lt;BR /&gt; Data.Amount + peek('Temp.Results'),&lt;BR /&gt; Data.Amount&lt;BR /&gt; ),&lt;BR /&gt; Data.Amount&lt;BR /&gt; ) as Results&lt;BR /&gt;resident Data&lt;BR /&gt;order by Data.Product asc,Data.Date desc;&lt;/B&gt;&lt;/P&gt;&lt;P style="font-weight: bold"&gt;unqualify *;&lt;/P&gt;&lt;P&gt;&lt;B&gt;//load positive results&lt;BR /&gt;Final:&lt;BR /&gt;load&lt;BR /&gt; Temp.Product as Product&lt;BR /&gt; ,Temp.Date as Date&lt;BR /&gt; ,Temp.Results as Amount&lt;BR /&gt;resident Temp&lt;BR /&gt;where Temp.Results &amp;gt;= 0;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;//get total amounts for products&lt;BR /&gt;NegativeProducts:&lt;BR /&gt;load&lt;BR /&gt; Temp.Product as Prod&lt;BR /&gt; ,sum(Temp.Amount) as Res&lt;BR /&gt;resident Temp&lt;BR /&gt;group by Temp.Product;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;&lt;B&gt;//clear temp from products with positive total amount&lt;BR /&gt;inner join (Temp) load&lt;BR /&gt; Prod as Temp.Product&lt;BR /&gt; ,Res as Temp.Results&lt;BR /&gt;resident NegativeProducts&lt;BR /&gt;where Res &amp;lt; 0;&lt;/B&gt;&lt;/P&gt;&lt;P style="font-weight: bold"&gt;//get rid of temporary table&lt;BR /&gt;drop table NegativeProducts;&lt;/P&gt;&lt;P&gt;&lt;B&gt;//add remaining negative values to Final table&lt;BR /&gt; concatenate(Final) load&lt;BR /&gt; Temp.Product as Product&lt;BR /&gt; ,Temp.Date as Date&lt;BR /&gt; ,Temp.Results as Amount&lt;BR /&gt;resident Temp;&lt;/B&gt;&lt;/P&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;B&gt;drop table Temp;&lt;BR /&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;Find attached a Qv file solving the problem.&lt;/P&gt;&lt;P&gt;Best wishes,&lt;/P&gt;&lt;P&gt;Valera&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Apr 2010 22:37:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Knock-Off-the-Negative-Value/m-p/210377#M64978</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-04-12T22:37:53Z</dc:date>
    </item>
    <item>
      <title>Knock Off the Negative Value ....</title>
      <link>https://community.qlik.com/t5/QlikView/Knock-Off-the-Negative-Value/m-p/210378#M64979</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Superb Buddy !!! &lt;IMG alt="Yes" src="http://community.qlik.com/emoticons/emotion-21.gif" /&gt; Looks Perfect ....!!! Thanks Thanks Thanks!!!!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me try it in my Scenario and i will get back to you if i have any queries..!!!!&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Deepak&lt;IMG alt="Big Smile" src="http://community.qlik.com/emoticons/emotion-2.gif" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Apr 2010 05:51:24 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Knock-Off-the-Negative-Value/m-p/210378#M64979</guid>
      <dc:creator>deepakk</dc:creator>
      <dc:date>2010-04-13T05:51:24Z</dc:date>
    </item>
  </channel>
</rss>

