How to Automatically Calculate Required Box Quantities in Excel
Question details
The user needs to dynamically calculate the number of boxes required to fulfill a product order based on varying box capacities per item.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Managing inventory, shipping, or packaging where different products have a different quantity of items per box, and the system needs to calculate total boxes needed for an order.
- Observed behavior
- The goal state is an automated spreadsheet setup where entering the product and total quantity required instantly returns the correct number of boxes needed, rounded up to the nearest whole box.
Ensure you have set up a clear lookup table in your worksheet, featuring one column for your product names and an adjacent column specifying the exact quantity of items that fit into one box for each product.
Use XLOOKUP and ROUNDUP for Box Calculation
Combine the XLOOKUP function to retrieve the quantity per box and the ROUNDUP function to ensure any fractional boxes are counted as full boxes.
This method is highly recommended for modern versions of Excel and WPS Office. XLOOKUP safely pulls the exact packaging data for the specific product, while ROUNDUP guarantees you don't run short on boxes by rounding fractions up.
Create a reference table on a sheet named 'Data'. Enter your product names in column A and the corresponding 'Quantity per Box' in column B.
In your main order sheet, select the cell where you want to show the items per box. Enter the formula: =XLOOKUP(A2, Data!A:A, Data!B:B) assuming A2 contains the product name ordered.
To find out how many boxes are needed, you must divide the total items needed by the items per box. Select the target cell and enter: =ROUNDUP(TotalRequired/QuantityPerBox, 0). The '0' tells Excel to round up to the nearest whole number.
To save space, you can nest the formulas into one cell: =ROUNDUP(TotalRequired / XLOOKUP(A2, Data!A:A, Data!B:B), 0).

Alternative Method using VLOOKUP and CEILING
If you are using an older spreadsheet version that does not support XLOOKUP, you can use VLOOKUP combined with the CEILING function.
Calculate Inventory Effortlessly with WPS Spreadsheet
WPS Spreadsheet fully supports advanced functions like XLOOKUP, VLOOKUP, and ROUNDUP. You can easily build dynamic lookup tables to manage inventory, packaging, and shipping without any compatibility issues.
- 1. Open Your Data: Launch WPS Spreadsheet and open your inventory or order management file.
- 2. Insert the Lookup Formula: Click on the target cell, navigate to the Formulas tab, and insert the XLOOKUP function to retrieve box capacities.
- 3. Nest the ROUNDUP Function: Edit the formula in the formula bar at the top to wrap your division calculation in a ROUNDUP function.
- 4. Apply to All Rows: Double-click the small green fill handle at the bottom right of your active cell to automatically calculate box quantities for your entire order list.

Frequently Asked Questions
Why do I need to use ROUNDUP instead of regular rounding?
Regular rounding (using the ROUND function) rounds down if the decimal is less than 0.5. However, in packaging, even if you only need 1 item that comes in a box of 10 (0.1 boxes), you still need to ship 1 full physical box. ROUNDUP ensures any partial box requirement correctly returns a full box.
What does an #N/A error mean in my lookup formula?
An #N/A error indicates that the spreadsheet cannot find an exact match for the product name in your lookup table. Check for typos, extra spaces before or after the product name, or ensure your lookup range encompasses all product entries.
Can I use index and match to calculate box quantities?
Yes. INDEX and MATCH is an excellent alternative to XLOOKUP and VLOOKUP. You would use =ROUNDUP(TotalRequired / INDEX(QuantityRange, MATCH(Product, NameRange, 0)), 0). This is especially useful in older versions of Excel where XLOOKUP isn't available.
How do I handle products that don't need boxes?
You can wrap your formula in an IFERROR or IF statement. For example, if a product is shipped loose, you can set the quantity per box as 1, or use =IF(B2="Loose", TotalRequired, ROUNDUP(...)) to bypass the box calculation for specific items.




