Actually I am more confused on your requirement and the solution approach you took than before.
On an implementation level you seems to wildly mix analytical views with scripted calc views, both CE-functions ans SQL commands.
I have the strong feeling that the usage of the different tools here is rather arbitrary and maybe founded on some believes like *CE functions are faster" and the like.
For me, in order to make a proper recommendation to solve the problem, the source data and the desired output are required.
To answer the short term question of how to access the previous' row values: try Window functions (LAG/LEAD).