I have a problem. I want to create a calculated column call ExpectedOutcome .
The value of column ExpectedOutcome for 1st row where No.Session = 1 is calculated by Score + 60.
From the second row, the value of ExpectedOutcome = previous ExpectedOutcome + Score.
The value of ExpectedOutcome is always in the range of 0 – 100. If it < 0, then we put 0 as the value. If it > 100, then we put 100 as the value.
It seems like calculate a running total, but it is not. And I do not know how to solve this problem.
3
Answers
Try This
This will work correctly for the same id:
This will do for different id’s:
Try out here: db<>fiddle
Here’s a solution with recursive CTE:
Tested with 2 IDs: