Qlik Community

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

cancel
Showing results for 
Search instead for 
Did you mean: 
marcel_olmo
Partner
Partner

Previous Read Row

Hi guys, I've the following example :

Field1Field2Result
1101
2202
3303,5
4405,5
5508

Where the field Result needs the value of the previous value of Result itself.

I know that you can get the previous value of Field1 or Field2 because there aren't the same column fields, but when is the same column, it says "error" because Qlik can't find the field "Result" because it doesn't even exist.

Here's the calculation I can't do in Qlik --> Result =(previous(Result)*2 + Field1 )/2

How can you do that?

I attack an excel example of what I mean.

Regards, Marcel.

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Have you even tried the script I've posted?

I am not loading the Result column, but calculating it from Field1 and the previous output table row only.

I do get Result 0.5 off, but that's what your expression returns.

edit: emphasized that peek() returns previous output table row and uploaded sample QVW

View solution in original post

8 Replies
maxgro
MVP
MVP

LOAD Field1,

     Field2,

     alt((previous(Result)*2 + Field1 )/2, Field1) as Result

FROM

[Prev Row Example.xlsx]

(ooxml, embedded labels, table is Hoja1);

swuehl
MVP
MVP

PEEK() can do what you want, addressing the output from the row loaded before:

LOAD Field1,

          Field2,

          Rangesum(Peek(Result)*2, Field1 )/2 AS Result

FROM ....;


edit: Corrected rangesum() arguments separated by comma

marcel_olmo
Partner
Partner
Author

Thanks Massimo for answering so quickly,

the point is that there's no Result column in my database, I have to calculate it from Field1 and Field2. This is an example trying to show what I'm trying to do.

My result field is something like :

if( rowno() =1,1, (previous(NewField) * 2 + Field1)/2 as NewField.

If you do that, Qlik says that "NewField" it doesn't exists.

How can you do that?

Regards, Marcel.

marcel_olmo
Partner
Partner
Author

Thanks swuehl,

I've just wrote the point of that in the answer before. There's no such Result field in the database, that's why Qlik doesn't let me do that.

I've attached what I mean.

Regards, Marcel.

swuehl
MVP
MVP

Have you even tried the script I've posted?

I am not loading the Result column, but calculating it from Field1 and the previous output table row only.

I do get Result 0.5 off, but that's what your expression returns.

edit: emphasized that peek() returns previous output table row and uploaded sample QVW

antoniotiman
Master III
Master III

Hi Marcel,

simply You add

If(RowNo() > 1,Swuel' expression,1) as Result

Regards

marcel_olmo
Partner
Partner
Author

Thanks swuehl,

I've got the issue there. If you use the function Previous() it says the field doesn't exist, but not the function peek().

Thanks a lot for your useful help.

Regards, Marcel.

maxgro
MVP
MVP


LOAD Field1,

     Field2,

     alt((peek(Result2)*2 + Field1 )/2, Field1) as Result2

FROM

[Prev Row Example.xlsx]

(ooxml, embedded labels, table is Hoja1);