Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Range Function

Hi everyone.

I've been reading up on the different row functions to help me accomplish my task by modifying the standard rangeavg syntax but the standard syntax seems incorrect?

I am trying to find the average of the 12 rows above the current row (not including it). Qlikview does not agree with the syntax of the rangeavg though.

Please can you assist me. Would also appreciate any advice if you feel there's a better way to approach this task. Later on I will be building on this to check if there are nulls or 0 values in any of the previous 12 rows and then dividing by less than 12 rows (in other words avoiding affecting the average by only dividing by rows that had a value greater than zero)

Many thanks.

"Prov Summary Temp":

Load
[Month Start],
[Scheme],
[Scheme Product],
[Claim Count],
rangeavg(above(sum([Claim Count]),1, 12)) as [Prov Avg]

7 Replies
swuehl
MVP

above() is a chart inter record function and can only be used in a chart, not in the script.

You can use multiple instances of peek() as arguments to rangeavg() to achieve what you want.

edit: For example:

LOAD *, rangeavg( peek(Value),peek(Value,-2),peek(Value-3))  as AVG  ;

LOAD recno() as Value

AutoGenerate 100;

Not applicable
Author

Hi!

Thank you for this!

I will incorporate your suggestion into my query and let you know how it goes..

Many thanks!


Not applicable
Author

Hi.

I tried out your suggestions but for some reason, even a basic peek function does not yield the correct results in my script.

It brings up very arbitrary values and nothing from the Claim Count column.

Load

[Month Start],

[Scheme],

[Scheme Product],

[Claim Count],

peek('Claim Count') as [peek test]

rangeavg(peek('Claim Count'), peek('Claim Count', 2), peek('Claim Count', 3)) as [Prov Avg]

Resident "Prov Summary"

Order by [Month Start],

         [Scheme],

         [Scheme Product];

Would appreciate your help.

Thank you.

hic
Former Employee

Use

rangeavg(peek('Claim Count'), peek('Claim Count', -2), peek('Claim Count', -3)) as [Prov Avg]

instead. (The minus signs.)

HIC

MayilVahanan

Hi

Try like this

rangeavg(peek('Claim Count'), peek('Claim Count', -2), peek('Claim Count', -3)) as [Prov Avg]

2   -> Takes Next Value
-2  -> Takes Previous Value

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
Not applicable
Author

Hi Henric / Mayil.

Thank you both for your assistance.

It still does not seem to work on my side. Below is my code and the results I am getting.

"Prov Summary Temp":

Load

[Month Start],

[Scheme],

[Scheme Product],

[Claim Count],

peek('Claim Count') as [Peek One Row Back],

peek('Claim Count', -2) as [Peek Two Rows Back],

peek('Claim Count', -3) as [Peek Three Rows Back],

rangeavg(peek('Claim Count'), peek('Claim Count', -2), peek('Claim Count', -3)) as [Prov Avg]

Resident "Prov Summary"

Order by [Month Start],

         [Scheme],

         [Scheme Product];

Results:

Month
  Start
SchemeClaim Count[Peek One Row
  Back]
[Peek Two Rows Back][Peek Three
  Rows Back]
Prov Avg
3626088041013808
2013/01/01Forevermed5280120170123
2013/02/01Forevermed265110013395
2013/03/01Forevermed3872128152117
2013/04/01Forevermed37668511288
2013/05/01Forevermed4281959289
2013/06/01Forevermed45627910883
2013/07/01Forevermed41698710286
2013/08/01Forevermed43647810482
2013/09/01Forevermed3762303944
2013/10/01Forevermed11211
Not applicable
Author

Hi everyone.

I figured out what was wrong - my column orders were affecting the peek.

Thank you.