Given a table of people and the score associated to their evaluation, I need to get their cumulative score (by person) for each evaluation.
Person | EvaluationDate | Score |
---|---|---|
Jane | 2012 | -12 |
Hubert | 2014 | -5 |
Jane | 2020 | -5 |
Jane | 2015 | +16 |
Hubert | 2011 | -100 |
Their scores start from 100 and cannot go below 0 or beyond 100. If at a certain time the score goes beyond 100 (or below 0), the next cumulative score is calculated from 100 (or 0).
Expected output :
Person | EvaluationDate | Score | CumulativeScore |
---|---|---|---|
Hubert | 2011 | -100 | 0 |
Hubert | 2014 | -5 | 0 |
Jane | 2012 | -12 | 88 |
Jane | 2015 | +16 | 100 |
Jane | 2020 | -5 | 95 |
There are posts describing how to do a cumulative sum but they do not explain how to restrict it to a range through each operation.