<?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 This Month values minus Last month values in script in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/This-Month-values-minus-Last-month-values-in-script/m-p/1688113#M593975</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;in a load script, I want to calculate the difference between "this month" sales and "last month" sales, where the "Elementname" is the same.&lt;/P&gt;&lt;P&gt;Tables looks like this:&lt;/P&gt;&lt;P&gt;Data:&lt;/P&gt;&lt;P&gt;Elementname,&lt;/P&gt;&lt;P&gt;Sales,&lt;/P&gt;&lt;P&gt;Date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;So written in words something like this:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;newData:&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;Elementname,&lt;/P&gt;&lt;P&gt;Sales,&lt;/P&gt;&lt;P&gt;Date,&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Sum("where Elementname = Elementname and date = date") - Sum("where Elementname = Elementname and Date=Addmonth(date,-1)") as "prSales"&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Example data could be:&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;AB,100,01.01.2020&lt;/P&gt;&lt;P&gt;AB,50,01.12.2019,&lt;/P&gt;&lt;P&gt;AC,100,01.02.2020&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Expected is this:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;100-50 (for AB)&lt;/P&gt;&lt;P&gt;100-0 (for AC, since there is no value from previous month)&lt;/P&gt;&lt;P&gt;How to do this?&lt;/P&gt;</description>
    <pubDate>Thu, 26 Mar 2020 13:25:50 GMT</pubDate>
    <dc:creator>HermGerm</dc:creator>
    <dc:date>2020-03-26T13:25:50Z</dc:date>
    <item>
      <title>This Month values minus Last month values in script</title>
      <link>https://community.qlik.com/t5/QlikView/This-Month-values-minus-Last-month-values-in-script/m-p/1688113#M593975</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;in a load script, I want to calculate the difference between "this month" sales and "last month" sales, where the "Elementname" is the same.&lt;/P&gt;&lt;P&gt;Tables looks like this:&lt;/P&gt;&lt;P&gt;Data:&lt;/P&gt;&lt;P&gt;Elementname,&lt;/P&gt;&lt;P&gt;Sales,&lt;/P&gt;&lt;P&gt;Date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;So written in words something like this:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;newData:&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;Elementname,&lt;/P&gt;&lt;P&gt;Sales,&lt;/P&gt;&lt;P&gt;Date,&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Sum("where Elementname = Elementname and date = date") - Sum("where Elementname = Elementname and Date=Addmonth(date,-1)") as "prSales"&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Example data could be:&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;AB,100,01.01.2020&lt;/P&gt;&lt;P&gt;AB,50,01.12.2019,&lt;/P&gt;&lt;P&gt;AC,100,01.02.2020&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Expected is this:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;100-50 (for AB)&lt;/P&gt;&lt;P&gt;100-0 (for AC, since there is no value from previous month)&lt;/P&gt;&lt;P&gt;How to do this?&lt;/P&gt;</description>
      <pubDate>Thu, 26 Mar 2020 13:25:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/This-Month-values-minus-Last-month-values-in-script/m-p/1688113#M593975</guid>
      <dc:creator>HermGerm</dc:creator>
      <dc:date>2020-03-26T13:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: This Month values minus Last month values in script</title>
      <link>https://community.qlik.com/t5/QlikView/This-Month-values-minus-Last-month-values-in-script/m-p/1694657#M593976</link>
      <description>&lt;P&gt;Are you looking like this?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;tab1:
LOAD *, MonthStart(Date#(Sales_Date,'DD.MM.YYYY')) As  Sales_MS INLINE [
	Elementname, Sales, Sales_Date
    AB, 100, 01.01.2020
    AB, 50, 01.12.2019
    AC, 100, 01.02.2020
];

tab2:
LOAD Elementname, Sales_MS, Sum(Sales) As Sales_Sum
Resident tab1
Group By Elementname, Sales_MS
;

Left Join (tab2)
LOAD Elementname, Count(Sales_MS) As MS_Count
Resident tab1
Group By Elementname
;

tab3:
LOAD Elementname, Sales_MS, If(MS_Count=1,Sales_Sum,If(Elementname=Peek(Elementname),Sales_Sum - Alt(Peek(Sales_Sum),0))) As Sales_Diff,
Sales_Sum , Peek(Sales_Sum) As Sales_Peek
Resident tab2
Order By Elementname, Sales_MS Asc
;

Drop Table tab1, tab2;&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 19 Apr 2020 01:16:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/This-Month-values-minus-Last-month-values-in-script/m-p/1694657#M593976</guid>
      <dc:creator>Saravanan_Desingh</dc:creator>
      <dc:date>2020-04-19T01:16:23Z</dc:date>
    </item>
  </channel>
</rss>

