• Typically I would add the SQL here but I'm running into a meeting...

    You could join the CTE to itself (aka make it recursive) but join each row to ROW# - 1, so ROW 1 would be joined to ROW 2, etc. Then you can do your math without needing the CASE statement.

    Just my 2 cents...