An easy way to replace lag()
is with a correlated subquery. Here is an example (simplified from your query):
SELECT date, action_id, inc_id,
(select top 1 usr_n
from table t2
where t2.inc_id < t.inc_id
order by t2.inc_id desc
) AS prevusr,
FROM table t;
If you want to calculate the lags of multiple variables at the same time you can use apply
.