I have a staffing formula that looks avoids excess capacity by choosing the minimum number needed over the next 12 weeks. The result is shown below (only using 10 weeks for simplicity here but actually need over 200 weeks). Currently, I have to manually enter the selected staffing one number at a time since I can't calculate the next number in the sequence until the correct number is staffed in the previous week. This is manual and prevent me from doing sensitivity analysis that dynamically adjusts staffing. I'm look for a solution to help automate it. I tried created a reference that counted up from 1 to 10 and would calculate until that week was reached and store the number (e.g. week 1 calculates 4 and is stored but all other weeks are ignored, then week 2 is calculated and stored and so on) but was unsuccessful. Any tips for how to achieve this or what to google for help? I haven't been able to find anything so far but may not being describing the problem effectively for a search.