Calculation Issues

How to Calculate Remaining Cartons and Bags with an Excel Formula

Olivia MillerOlivia Miller Nov 10, 2026 869 views

Question details

The user needs an Excel formula to accurately calculate remaining inventory stored in cartons and bags after individual bags are consumed.

How to Calculate Remaining Cartons and Bags in Excel
Product
Excel / WPS Spreadsheet
Device & OS
not provided
Scenario
Tracking a two-tiered inventory system (e.g., cartons and loose bags) where consuming smaller units (bags) must dynamically reduce the larger unit (carton) count and display the correct remaining balance.
Observed behavior
A dynamic formula is required to automatically convert total remaining stock back into correct carton and bag quantities based on a specific conversion rate (e.g., 20 bags per carton).
Before you start

Ensure your inventory data is organized into clear columns for starting cartons, starting bags, used bags, and the specific number of bags per carton before applying the formula.

Solution 1Recommended

Use LET and HSTACK Functions for Dynamic Inventory Calculation

This method uses advanced dynamic array functions to simultaneously calculate and output both remaining cartons and remaining bags in adjacent cells.

By utilizing the LET function, you can define the total remaining bags once to keep the formula clean. The HSTACK function then arrays the results for cartons and bags horizontally.

The formula calculates the total initial bags, subtracts the used amount, and converts the remainder back into cartons and bags.

1
Set up your data layout

Ensure your data is placed in specific cells: A2 for Starting Cartons, B2 for Starting Bags, C2 for Bags Used, and G2 for Bags per Carton (e.g., 20).

2
Select the target cell

Click on the cell where you want the remaining cartons to appear (for example, D2). Keep the cell to its immediate right (E2) empty to allow the formula to spill the remaining bags.

3
Enter the dynamic formula

Type the following formula into the formula bar: =LET(Remaining, G2*A2+B2-C2, HSTACK(QUOTIENT(Remaining-1, G2), MOD(Remaining-1, G2)+1))

4
Apply the calculation

Press Enter. The cell D2 will display the remaining cartons, and the adjacent cell E2 will automatically display the remaining bags.

Use LET and HSTACK Functions for Dynamic Inventory Calculation
Dynamic Arrays: HSTACK is a dynamic array function. Ensure you have enough empty space in the adjacent cell to prevent a #SPILL! error.
Advanced Spreadsheet Tool

Manage Your Inventory Effortlessly with WPS Spreadsheet

WPS Spreadsheet fully supports dynamic arrays and advanced formulas like LET and HSTACK, making complex two-tiered inventory calculations simple and highly efficient.

  1. 1. Open WPS Spreadsheet: Launch WPS Office and create a new inventory tracking workbook.
  2. 2. Organize your data: Input your inventory data into designated columns: Initial Cartons, Initial Bags, Used Bags, and Bags per Carton.
  3. 3. Apply the formula: Paste the provided LET and HSTACK formula into the target cell where you want to calculate the remaining stock.
  4. 4. View automated results: Press Enter to instantly view your updated carton and bag counts in adjacent columns.
Fully compatible with Microsoft Excel formulas and file formats (.xlsx).Supports advanced dynamic array functions for complex data analysis.Free and lightweight alternative to heavy office suites.Clean interface for smooth inventory tracking and management.
microsoft office alternative - wps office

Frequently Asked Questions

Why am I getting a #NAME? error when using the LET function?

The #NAME? error occurs if your version of Excel or spreadsheet software does not support the LET or HSTACK functions, which are available in newer versions. If you are using an older version, use the separate INT and MOD formulas provided in the alternative solution.

What does the MOD function do in this inventory formula?

The MOD function calculates the remainder after a division. In this inventory context, it determines exactly how many loose bags remain after dividing the total remaining bags by the number of bags in a full carton.

How can I prevent a #SPILL! error when using HSTACK?

A #SPILL! error happens when there is existing data blocking the formula from outputting its results into adjacent cells. Ensure the cell immediately to the right of your formula (where the remaining bags will be displayed) is completely empty.