Running total for 2 different calculations/logic

I’m facing an issue where the last 3 rows i.e. Gap(m-1),% M-1 and Cumulative are custom rows inserted and the rest are the datasets which have been dragged and dropped without any issues.

so coming onto the issue, I’m making a running total for the column months where the Month column either matches the max record for PSI i.e. here it’s “PSI 29 Jul’24”.
Hence Jul’24,Aug’24 and Sep’24 are supposed to show.

Now the twist here is that if the column month is matching with the max PSI value then different calculation is used. logic here is the maximum value of max month available row wise -

and for rest of the months beyond max psi month value i.e. Jul’24 it has the following logic:-

How do i combine 2 different calculations so i can mae a single running total and show it accurately in % M-1 row.

Help would be appreciated.! :slight_smile: