Skip to main content Skip to complementary content

Previous - script function

Previous() finds the value of the expr expression using data from the previous input record. In the first record of an internal table, the function will return NULL.

Syntax:  

Previous(expr)

Return data type: dual

Arguments:  

Previous arguments
Argument Description
expr The expression or field containing the data to be measured.

The expression can contain nested previous() functions in order to access records further back. Data are fetched directly from the input source, making it possible to refer also to fields that have not been loaded into QlikView, that is,even if they have not been stored in its associative database.

Limitations:  

In the first record of an internal table, the function returns NULL.

Example 1:  

Sales2013:

Load *, (Sales - Previous(Sales) )as Increase Inline [

Month|Sales

1|12

2|13

3|15

4|17

5|21

6|21

7|22

8|23

9|32

10|35

11|40

12|41

] (delimiter is '|');

 

By using the Previous() function in the Load statement, we can compare the current value of Sales with the preceding value, and use it in a third field, Increase.

Example 1 results
Month Sales Increase
1 12 -
2 13 1
3 15 2
4 17 2
5 21 4
6 21 0
7 22 1
8 23 1
9 32 9
10 35 3
11 40 5
12 41 1

Example 2:  

Sales2013:

Load * Inline [

Month|Sales

1|12

2|13

3|15

4|17

5|21

6|21

7|22

8|23

9|32

10|35

11|40

12|41

] (delimiter is '|');

 

Sales:

NoConcatenate Load *, (Sales - Previous(Sales) )as Increase Resident Sales2013 where Month > 6;

 

Drop Table Sales2013;

 

In this example we exclude the records where Month is 6 or less by using a WHERE clause. This still makes it possible to use Previous() as the function can refer to data that is excluded from the load.

In this case the calculation of Increase for Month=7 refers to the Sales value for Month=6, which is excluded from the load.

Example 2 results
Month Sales Increase
7 22 1
8 23 1
9 32 9
10 35 3
11 40 5
12 41 1

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!

Join the Analytics Modernization Program

Remove banner from view

Modernize without compromising your valuable QlikView apps with the Analytics Modernization Program. Click here for more information or reach out: ampquestions@qlik.com