Getting the row before a row with a certain value in SQL
The steps to do this are actually pretty simple in any SQL variant that supports LAG:

Pull out the previous action_name using LAG, in a derived table or CTE.
Filter on the outside to only rows which contain 'reference_action', these rows will also have the previous action from the first step. You want to do this on the outside, otherwise you won't get the correct LAG values.
Group by the previous action, and count.

SELECT
    prevAction AS action,
    COUNT(*) AS [count]
FROM (
    SELECT *,
        LAG(action_name) OVER (ORDER BY timestamp) AS prevAction -- you may want a PARTITION also
    FROM YourTable
) AS t
WHERE action_name = 'reference_action'
GROUP BY prevAction;