Qlik Community

New to QlikView

Discussion board where members can get started with QlikView.

Announcements
Attend QlikWorld 2020 and hear keynote speaker, Malcolm Gladwell. Register by February 29th to save $200. Learn More
Highlighted
Not applicable

sum of current year and previous year sales in script

Hi Team,

I want a field year and sales. I want to create a new field accumulatesales which should be sum of current year sales + previous year sales.

How to create this new field in the script?

Please provide your suggestions.

Thanks,

SV

3 Replies
hemhund2016
Contributor

Re: sum of current year and previous year sales in script

Hi,

Use this.

Table_Sales:

LOAD year,

           sum(sales) as sales,

           from ****YOUR SOURCE**;

left join(Table_Sales)

LOAD year,

           sum(sales) +Previous(sales) as New_Sales

           Resident

           Temp_Sales

          order by year asc;

Highlighted
MVP
MVP

Re: sum of current year and previous year sales in script

it depends on your data

this could be a solution

1.png


z:

load * inline [

Year, Sales

2010, 100

2011, 110

2012, 120

2013, 130

2014, 140

2015, 100

];

zz:

load Year, Sales + Previous(Sales) as TwoYearSales Resident z order by Year;



Highlighted
Not applicable

Re: sum of current year and previous year sales in script

test1:

load * inline [

year, Sales

];

test2:

load year,

if(IsNull(Sales + Previous(Sales)),Sales,(Sales + Previous(Sales))) as PreviousSales

Resident z Order by Year;