THE DATA:
I'm trying to create a resource allocation file in Excel and have data structured as follows:
| Role | Person | Week 1 Availability |
|---|---|---|
| A | Sarah | 3 |
| A | John | 3 |
| A | Bill | 2 |
| A | Emily | 0.5 |
| A | Leah | 0.5 |
| A | Mike | 0.25 |
THE GOAL:
Let's say, for example, for Week 1 of my project, I need a total of 7 hours of work done. I need to select which employees have the availability to meet this quota. We can see by eye that Sarah, John, Emily, and Leah have 7 hours of combined availability, but I am trying to write a formula that will call these names together.
PREVIOUS IDEA #1: SUM and OFFSET
I first tried to create a complex function that used SUM and OFFSET to create a sequential sum, incrementing by one person at a time until I reached 7 or over 7. The formula would start with Sarah's availability of 3, then add John's availability of 3 (6 total), then add Bill's availability of 2 (8 total), and then stop and tell me I've reached 8 hours. Drawback: This obviously isn't perfect because we know there's an existing combo that gets us to exactly 7, but because I am summing sequentially, the formula doesn't account for this.
PREVIOUS IDEA #2: XLOOKUP and LARGE
Realizing I had positional constraints with my first attempt, I next tried to use the LARGE function in combination with XLOOKUP to create a sum that wasn't necessarily based on physical position, but on rank. The formula would first subtract the largest availability from what was needed (7 - 3, in our example) and if that was > 0, it would call the employee's name with XLOOKUP and then further subtract the 2nd largest availability from what was still needed. Drawback: Continuation of the formula is my issue here. I want it to say "If 7 minus the largest availability is greater than 0, then subtract the 2nd largest availability. If the result is still greater than 0, subtract the 3rd largest availability, etc. If, however, subtracting the 3rd largest availability results in a number less than 0, then subtract the 4th largest availability instead of the 3rd and check if that result is still above 0, etc.
How can I resolve my first two attempts to reach my desired outcome? Or is there a better solution altogether?! Note that once I have logic figured out, I'm looking to implement some macros to automate some of this process.
Thanks!
edited: spelling and grammar

