google-sheets

How to create a drop-down list with a maximum quantity?


I need to create Google spreadsheets to organize my son's end-of-year party. We have defined the dishes to bring and the quantity based on the number of participants.

So I have a list like this:

Foods Maximum Quantity
Sandwiches 60
Pizza 4
Savory pies 10
Desserts 10
Drinks 30

I would like to create a drop-down list starting from this list and have users enter the quantities, forcing them to stay within the range.

For example, the first person enters that they will bring 30 sandwiches, the second would like to bring 40 but must be able to enter a maximum of 30, and after this limit no one else must be able to enter any sandwiches.

Is it possible to do it? If so, how?

Thanks in advance


Solution

  • This method uses two formulas to produce horizontal arrays (shown in purple) containing the dropdown options for the corresponding rows (shown in blue) containing the Food Item dropdowns and the Quantity dropdowns.

    Visual showing the dropdowns and their respective array of options.

    In order to have these array of options be assigned to the dropdowns row by row, it's important to make sure the criteria range is using relative row values (without the $ sign in front of the row numbers). When you first create these rules, Sheets will always use absolute reference on both the column and the rows, no matter how you enter the range. You must go back into the rule settings, remove the $ from the row numbers and click Done.

    Food Item Dropdow Options Formula

    =LAMBDA(itemsSelected, quantitiesPromised, foodChoices, maxQuantities,
      MAP(itemsSelected, LAMBDA(item,
        {TOROW(
          FILTER(foodChoices,
            SUMIF(itemsSelected, foodChoices, quantitiesPromised) < maxQuantities)),
         item})))
    (B8:B19, C8:C19, E2:E6, F2:F6) 
    

    For each food item dropdown, the formula lists all the food items that are still needing people to sign up to bring using FILTER and SUMIF. This list is laid out horizontally along with the current selected item to avoid the red error flag in the dropdown. Once the requested quantity for an item is met, that item won't appear in the other dropdowns.

    Quantity Dropdown Options Formula

    =LAMBDA(itemsSelected, quantitiesPromised, foodChoices, maxQuantities,
      MAP(itemsSelected, quantitiesPromised, LAMBDA(selectedItem, selectedQuantity,
        IF(LEN(selectedItem),
          LET(maxQty, XLOOKUP(selectedItem, foodChoices, maxQuantities),
              upperLimit, MIN(maxQty, maxQty - 
                SUMIF(itemsSelected, selectedItem, quantitiesPromised) + selectedQuantity),
            IFERROR(SEQUENCE(1, upperLimit, upperLimit, -1))),
        ))))
    (B8:B19, C8:C19, E2:E6, F2:F6)
    

    Once an item is selected, the maximum quantity is found using XLOOKUP. An upper limit for the dropdown is calculated by taking the minimum of the maximum quantity and the maximum quantity minus the number that people have said they would bring, plus the selected amount for this specific dropdown. That result is used to created a horizontal sequence of numbers decending all the way down to zero.

    This upper limit gives the user the opportunity to both increase or decrease from their current amount, if available. Once the requested quantity for a food item has been met, the quantity dropdown will show all numbers less than or equal to the selected amount.

    Here is the demo spreadsheet shown in the image above: Party Sign-up