Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
microwin88x
Creator III
Creator III

Add Value from Last Year in Table

Hello,

I have the following table:

     - Period: YYYYMM

PeriodValue
20150110
20150215
2015035
20150420
20150525
20150630
201507100
201508150
201509135
201510500
201511200
201512235
2016015
20160215
20160320
20160450
20160545
20160695
20160770
201608750
201609200
201610250
201611380
201612355

What I need is to create a table like this:

PeriodValuePrevious_Value
201601510
2016021515
201603205
2016045020
2016054525
2016069530
20160770100
201608750150
201609200135
201610250500
201611380200
201612355235

This table contains last 12 months with the corresponding VALUE and the PREVIOUS_VALUE from last year.

Do you know how could I do this, directly on my Straight Table as an expression?

Thank you!!!

1 Solution

Accepted Solutions
sunny_talwar

One way is to use the Above() function

Capture.PNG

View solution in original post

5 Replies
sunny_talwar

One way is to use the Above() function

Capture.PNG

sunny_talwar

Second method using The As-Of Table

Frank_Hartmann
Master II
Master II

or just add this line in skript to your table:

peek(Value,-12) as prevValue

hope this helps

ziadm
Specialist
Specialist

Fourth Way

make the next year as Key and left join resident

Table1:

load * ,

AddYears(Date#(Year, 'YYYYMM'),1) as NextYear,

Date#(Year, 'YYYYMM') as YearMonth;

LOAD * Inline [

Year, Value

201501, 10

201502, 15

201503, 5

201504, 20

201505, 25

201506, 30

201507, 100

201508, 150

201509, 135

201510, 500

201511, 200

201512, 235

201601, 5

201602, 15

201603, 20

201604, 50

201605, 45

201606, 95

201607, 70

201608, 750

201609, 200

201610, 250

201611, 380

201612, 355 ];

left join

load NextYear as YearMonth,

Value as LastYearValue

Resident Table1;

ziadm
Specialist
Specialist

My way faster no calculation if you are loading big size data also you can combine another Key with YearMonth Field.. For example your key could be YearMonth + ProductID so the aggregation by Product