Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Kohli
Creator II
Creator II

compare the past 3 years salaries

I have table like these 

LineNO              EmployeeID          StartDate           EndDate                sales

1                   1.00                1/1/2008 00:00:00   31/12/2008 00:00:00 100000    

2                   1.00                1/1/2009 00:00:00   31/12/2009 00:00:00 110000    

3                   1.00                1/1/2010 00:00:00   31/12/2010 00:00:00 120000    

4                   1.00                1/1/2011 00:00:00   31/12/2011 00:00:00 130000    

5                   1.00                1/1/2012 00:00:00   31/12/2012 00:00:00 140000    

6                   1.00                1/1/2013 00:00:00   31/12/2013 00:00:00 150000    

7                   1.00                1/1/2014 00:00:00                                     160000    

8                   2.00                1/4/2010 00:00:00   31/12/2010 00:00:00 35000     

9                   2.00                1/1/2011 00:00:00   31/12/2011 00:00:00 36050     

10                  2.00                1/1/2012 00:00:00   31/12/2012 00:00:00 37132     

11                  2.00                1/1/2013 00:00:00   31/12/2013 00:00:00 38246     

12                  2.00                1/1/2014 00:00:00                                      39393     

13                  3.00                1/1/2008 00:00:00   31/12/2008 00:00:00 65000     

14                  3.00                1/1/2009 00:00:00   31/12/2009 00:00:00 75000     

15                  3.00                1/1/2010 00:00:00   31/12/2010 00:00:00 77250     

16                  3.00                1/1/2011 00:00:00   31/12/2011 00:00:00 79568     

17                  3.00                1/1/2012 00:00:00   31/12/2012 00:00:00 81955     

18                  3.00                1/1/2013 00:00:00   31/12/2013 00:00:00 84414     

19                  3.00                1/1/2014 00:00:00                                      86946     

i want compare the past 3 years sales...

output like:

EmpID, 2012,2013,2014

1,  140000,150000'160000

2, 37312,38246, 39393

.....

can you please write the script for that,

7 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

Add a Year field during your load:

LOAD LineNo,

     EmployeeID,

    Year(StartDate) as Year,

     ...

Then use Year and EmployeeID as dimensions and Sum(sales) as the expression in a pivot table. Click and drag the Year dimension to the top of the pivot table.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
Kohli
Creator II
Creator II
Author

i have 2011,2012,2013, 2104 and 2015 years in Years field. I want only 2015,2014,2013 years .sales in same pivot table

Kohli
Creator II
Creator II
Author

iam trying this one also. but it is coming all years

Sum({<YEAR={">=$(=YEAR(Max([Sal StartYear]),-3))<=$(=Max(Sal StartYear))"}>} Sales)

sushantwanjari
Contributor
Contributor

Hi,

Check if the date fields are loaded properly.

The following expression worked for me

=SUM( {<Year_Start = {"> $(=Max(TOTAL Year_Start) -3) <= $(=Max(TOTAL Year_Start)) "}>} sales)


Last3YrsSales.PNG



Hope this helps you..

-Sushant

sergio0592
Specialist III
Specialist III

Try with :

Sum({<YEAR={">=$(=YEAR(Max([Sal StartYear]))-3)<=$(=Max(Sal StartYear))"}>} Sales)

vishsaggi
Champion III
Champion III

May be you can try like:

= Sum({< YearField = {">=$(=Year(Today())-3)"} >}DollarAmount)

OR this:

= Sum({< YearField = {">$(=Max(YearField)-3)"} >}sales)

Anonymous
Not applicable

Hi,

You can use below script:

Test:

LOAD

     max(year(StartDate)) as MaxYear

FROM

[..\Test_Data.xlsx]

(ooxml, embedded labels, table is Sheet1);



LET vMaxYear = peek('MaxYear',0);


[Final Data]:

LOAD LineNO,

     EmployeeID,

     StartDate,

     EndDate,

     sales,

     year(StartDate) as Year

FROM

[..\Test_Data.xlsx]

(ooxml, embedded labels, table is Sheet1)

where year(StartDate) > $(vMaxYear)-3;


This will give you only last 3 years.