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

Announcements
Posting on Qlik Community is temporarily paused. Thank you for patience and we'll update you soon!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

previous period in script

Hi,

I would like to create a data model where the sum(measure) of previous period (measure_LY) is pre-calculated in the script:

so if i have the following input table...

  

periodgroupmeasure
1-1-2015A80
1-1-2015B90
1-1-2015C15
1-1-2014D30
1-1-2014A20

... the the parallel period is defined as follow

 

periodprev_period
1-1-20151-1-2014

the desired output should be

 

periodgroupmeasuremeasure LY
1-1-2015A8020
1-1-2015B90
1-1-2015C15
1-1-2015D30

please note the period can be anything from day to year interval

please help...

Dror

Labels (1)
6 Replies
its_anandrjs
Champion III
Champion III

Hi,

Better you use SET analysis expression here in the chart for previous value fetching.

Regards

Anand

MK_QSL
MVP
MVP

Data:

Load

  Date(Date#(period,'D-M-YYYY')) as period,

  group,

  measure

Inline

[

  period, group, measure

  1-1-2015, A, 80

  1-1-2015, B, 90

  1-1-2015, C, 15

  1-1-2014, D, 30

  1-1-2014, A, 20

];

Left Join(Data)

Load

  AddYears(period,1) as period,

  group,

  measure as LastYearMeasure

Resident Data;

Not applicable
Author

Manish,

Thanks for your reply.

You miss however group D. group D existed in 2014 but not in 2015 and should be taken in to account in the total of LastYearMeasure

That's the core of my problem...

Not applicable
Author

I know it can be solved on a chart level but from various reasons  i would like to keep it on the script level

MK_QSL
MVP
MVP

Data:

Load

  Date(Date#(period,'D-M-YYYY')) as period,

  group,

  measure

Inline

[

  period, group, measure

  1-1-2015, A, 80

  1-1-2015, B, 90

  1-1-2015, C, 15

  1-1-2014, D, 30

  1-1-2014, A, 20

];

Outer Join(Data)

Load

  AddYears(period,1) as period,

  group,

  measure as LastYearMeasure

Resident Data Where Year(AddYears(period,1)) <= Year(Today());

Not applicable
Author

That's it:) THANKS!!!