Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Not applicable

Getting the previous row and calculate.

Hello and Good Day, I'm currently new in QlikView and I say this is one powerful B.I Tool.

I'm still learning and I need to solve something..

I have a table

DIDValueValue1
D112000 0
D213000 1000
D322000 0
D421500 -500
D52500-1000
D631000..

I need to compute for Value1 depending on the ID.

The computation is d2-d1, d4-d3, d5-d4

I find it hard to explain, but I just need to compute for Value1 depending on the next Value.

Thank you and Good Day.

P.S This is for scripting Thank you.

1 Solution

Accepted Solutions
Not applicable

Re: Getting the previous row and calculate.

Hello,

from

if([Plate Number] = Peek([Plate Number]), [Odometer Reading] - Peek([Odometer Reading],0)) as peek

why Peek([Odometer Reading],0))?

Do you really want substract the first value from the table in every row?

left join(A)

LOAD

    Date,

    Time,

    if([Plate Number] = Previous([Plate Number]), [Odometer Reading] - Previous([Odometer Reading])) as new_peek

Resident

    A

Order by Date, Time;

I have an expample enclosed.

19 Replies
christophebrault
Valued Contributor

Re: Getting the previous row and calculate.

Hi,

I d'ont really understand your need.

How are your data when you load it, and what do you expect to do in the script exactly ?

Not applicable

Re: Getting the previous row and calculate.

it is from excel file. i loaded it.. and it has a lot of sheets.. so there is a for loop inside..

I have a field I need to compute. As I have said above, the results should be like this:

ID          Value     Value1

1           1000          0

1            2000      1000

1             500          -1500

2            100          0

2             200         100

perumal_41
Valued Contributor II

Re: Getting the previous row and calculate.

Hi,

Try this  expression  in Value

above([Value])-[Value]

use this expression ,u get result

Not applicable

Re: Getting the previous row and calculate.

Hi, I will try this in the expression, but I prefer it in the script

christophebrault
Valued Contributor

Re: Getting the previous row and calculate.

You can use this :

If(Peek(ID)=ID,

     Value-Peek(Value),0) as Value1,

Make sure your data are ordered by ID.

Not applicable

Re: Getting the previous row and calculate.

I will try this one, can you give me an example if possible? thank you

Not applicable

Re: Getting the previous row and calculate.

I tried your computation, yes it is working but the first value should be the one with the '-'

Not applicable

Re: Getting the previous row and calculate.

bump.

Not applicable

Re: Getting the previous row and calculate.

bump

Community Browser