If you want to get rid of the values, the loop sounds alright along with the function First(). To calculate the rank for all the rows, you don't need to use the loop if you order the whole table by Annual Deal Value and MonthYear and then use the inter-row functions like previous or peek to keep a counter that will be your rank and to know when the month changes to start the counter over again. Also, you can do it in the GUI with the something like the following formula:
sum( aggr( if( rank( sum(Sales), 4, 1) < 25, sum(Sales), 0),MonthYear)
The big question I have is how are you going to do a bar chart with 2 stacked bars that depend on different dimensions? You are going to have to separate it into 2 separate bar charts.