Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
qlikview979
Specialist
Specialist

Functions

Hi experts,

How to use peek,previous in functions script level?explain with example?

1 Solution

Accepted Solutions
Anonymous
Not applicable

The Peek  function is an inter-record function that allows us to literally peek into previously-read records of a table and use its values to evaluate a condition or to affect the active record (the one being read).

The function takes one mandatory parameter, the field name into which we will "peek", and two optional parameters, a row reference and the table in which the field is located.

For example, an expression like:

       1.   Peek('Date', -2) :>>> This expression will go back two records in the currently-being-read table, take the value on the Date field and use it as a result of the expression.

2.     peek( 'Price', 2 )  :>>> It returns the value of Price from the third record read from the current internal table.

3.   peek( 'Price', 0, 'Tab1' ) :>>> It returns the value of Price from the first record read into the input table labeled Tab1.

Previous Function:

There are certainly some similarities between the two functions but there are also distinct differences that need to be taken into account when deciding which function to use.

The Similarities

  • Both allow you to look back at previously loaded rows in a table.

  • Both can be manipulated to look at not only the last row loaded but also previously loaded rows.

The Differences

  • Previous() operates on the Input to the Load statement, whereas Peek() operates on the Output of the Load statement. (Same as the difference between RecNo() and RowNo().) This means that the two functions will behave differently if you have a Where-clause.

  • The Peek() function can easily reference any previously loaded row in the table using the row number in the function  e.g. Peek(‘Employee Count’, 0)  loads the first row. Using the minus sign references from the last row up. e.g. Peek(‘Employee Count’, -1)  loads the last row. If no row is specified, the last row (-1) is assumed.  The Previous() function needs to be nested in order to reference any rows other than the previous row e.g. Previous(Previous(Hires))  looks at the second to last row loaded before the current row.

So, when is it best to use each function?

  • The previous() and peek() functions could be used when a user needs to show the current value versus the previous value of a field that was loaded from the original file.

  • The peek() function would be better suited when the user is targeting either a field that has not been previously loaded into the table or if the user needs to target a specific row.

View solution in original post

3 Replies
Anonymous
Not applicable

The Peek  function is an inter-record function that allows us to literally peek into previously-read records of a table and use its values to evaluate a condition or to affect the active record (the one being read).

The function takes one mandatory parameter, the field name into which we will "peek", and two optional parameters, a row reference and the table in which the field is located.

For example, an expression like:

       1.   Peek('Date', -2) :>>> This expression will go back two records in the currently-being-read table, take the value on the Date field and use it as a result of the expression.

2.     peek( 'Price', 2 )  :>>> It returns the value of Price from the third record read from the current internal table.

3.   peek( 'Price', 0, 'Tab1' ) :>>> It returns the value of Price from the first record read into the input table labeled Tab1.

Previous Function:

There are certainly some similarities between the two functions but there are also distinct differences that need to be taken into account when deciding which function to use.

The Similarities

  • Both allow you to look back at previously loaded rows in a table.

  • Both can be manipulated to look at not only the last row loaded but also previously loaded rows.

The Differences

  • Previous() operates on the Input to the Load statement, whereas Peek() operates on the Output of the Load statement. (Same as the difference between RecNo() and RowNo().) This means that the two functions will behave differently if you have a Where-clause.

  • The Peek() function can easily reference any previously loaded row in the table using the row number in the function  e.g. Peek(‘Employee Count’, 0)  loads the first row. Using the minus sign references from the last row up. e.g. Peek(‘Employee Count’, -1)  loads the last row. If no row is specified, the last row (-1) is assumed.  The Previous() function needs to be nested in order to reference any rows other than the previous row e.g. Previous(Previous(Hires))  looks at the second to last row loaded before the current row.

So, when is it best to use each function?

  • The previous() and peek() functions could be used when a user needs to show the current value versus the previous value of a field that was loaded from the original file.

  • The peek() function would be better suited when the user is targeting either a field that has not been previously loaded into the table or if the user needs to target a specific row.
Anonymous
Not applicable

see the attached zipfile for the example

Anonymous
Not applicable

does this help you Mahesh