Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Question about function Previous()

Hi,

please, look at my script:

load

  id,

  text,

  balance,

  Previous(debt) - balance as debt

;

load * inline [

id, text, balance, debt

0,,,400

1, aaa, 250, 0

2, bbb, 200, 0

3, ccc, 100, 0

];

I expected this:

0,       ,      , -

1, aaa, 250, 150

2, bbb, 200, -50

3, ccc, 100, -150

but, result is:

0,       ,      , -

1, aaa, 250, 150

2, bbb, 200, -200

3, ccc, 100, -100

What's wrong in my script?

Thanks in advance!

3 Replies
prat1507
Specialist
Specialist

Previous(debt) returns

-

400

0

0

which when evaluated as Previous(debt)-balance gives

-

150

-200

-100

Regards

Pratyush

vinieme12
Champion III
Champion III

Debt is 0 for all except the first row, I think you want this

Load

  id,

  text,

  balance,

  balance - Previous(balance) as debt

;

load * inline [

id, text, balance, debt

0,,400,

1, aaa, 250, 0

2, bbb, 200, 0

3, ccc, 100, 0

];

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
settu_periasamy
Master III
Master III

Try this..

Load
id,
text,
balance,
Previous(balance) as Prev,
if(RowNo()>2, Peek(dept)-balance,Previous(balance)-balance) as dept
;