Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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, the result is
0, , , -
1, aaa, 250, 150
2, bbb, 200, -200
3, ccc, 100, -100
what's wrong?
thanks in advance!
Try this,
Data:
LOAD *,If(Rowno()=1, debt,Peek(Bal)-balance) as Bal;
load * inline [
id, text, balance, debt
0,,, 400
1, aaa, 250, 0
2, bbb, 200, 0
3, ccc, 100, 0
];
Final:
NoConcatenate
Load id,text,balance,debt,if(debt=Bal,0,Bal) as Value Resident Data;
drop Table Data;
Regards,
Kaushik Solanki
Try this,
Data:
LOAD *,If(Rowno()=1, debt,Peek(Bal)-balance) as Bal;
load * inline [
id, text, balance, debt
0,,, 400
1, aaa, 250, 0
2, bbb, 200, 0
3, ccc, 100, 0
];
Final:
NoConcatenate
Load id,text,balance,debt,if(debt=Bal,0,Bal) as Value Resident Data;
drop Table Data;
Regards,
Kaushik Solanki
Many thanks, Kaushik!
Works good!
Hi Oleg
Do you know why this has happened???
That Previous() function gives you a different Result from Peek() function.
This has happened because of the below Reson:
Previous() operates on the Input to the Load statement,
whereas Peek() operates on the Output of the Load statement.
So, when is it best to use each function?
See the detailed description here:
Peek() vs Previous() – When to Use Each
Hope that has given you some conceptual Clarity.
Regards
Av7eN