Create an Automatic Gain or Loss Column in an Excel Table
Question details
Create a calculated table column that subtracts planned tonnage from produced tonnage and stays blank if either source value is empty.

- Product
- Microsoft Excel table
- Device & OS
- not provided
- Scenario
- The user wants to compare planned and produced quantities for each row in a structured table.
- Observed behavior
- A positive value should indicate production above plan, a negative value should indicate a shortfall, and incomplete rows should display no result.
Make sure the data is formatted as an Excel Table and that the headers are named Planned Tonnage and Produced Tonnage. Confirm that the quantity cells contain numbers when values are available.
Use an IF formula to calculate gain or loss only when both values exist
Use this formula in the new calculated column when you need each table row to show the produced-minus-planned difference without displaying zero or an error for incomplete records.
The formula checks whether either input cell is blank before performing the subtraction. Excel Table structured references automatically apply the formula to the rest of the calculated column.
In the Excel Table, insert a new column and enter a header such as Gain or Loss.
Select the first data cell under Gain or Loss and enter =IF(OR([@[Planned Tonnage]]="",[@[Produced Tonnage]]=""),"",[@[Produced Tonnage]]-[@[Planned Tonnage]]).
Press Enter. Excel should fill the formula down the calculated column automatically; if it does not, copy the formula down the remaining table rows.
Review the Gain or Loss values: a positive number means produced tonnage exceeded the plan, while a negative number means production was below plan.

Calculate Gain or Loss Automatically in WPS Spreadsheets
WPS Spreadsheets supports Excel-style tables and structured-reference formulas, so you can create a Gain or Loss column that compares produced and planned tonnage while leaving incomplete rows blank.
- 1. Open the workbook in WPS Spreadsheets: Launch WPS Office, choose Spreadsheets, and open the Excel workbook containing the planned and produced tonnage table.
- 2. Create the output field: Click the table header area, add a column beside the source values, and name it Gain or Loss.
- 3. Insert the blank-safe calculation: Select the first result cell and type =IF(OR([@[Planned Tonnage]]="",[@[Produced Tonnage]]=""),"",[@[Produced Tonnage]]-[@[Planned Tonnage]]).
- 4. Fill and review the results: Press Enter to apply the formula, then verify that positive values show gains, negative values show shortfalls, and rows with missing inputs remain blank.

Frequently Asked Questions
Why does the Gain or Loss cell stay blank even though I entered one quantity?
The formula is designed to return a blank when either Planned Tonnage or Produced Tonnage is empty. Enter numeric values in both table columns to calculate the difference.
How do I show a loss as a negative number in an Excel table?
Subtract planned from produced: [@[Produced Tonnage]]-[@[Planned Tonnage]]. When produced tonnage is lower than planned tonnage, the result is negative automatically.
Can I use this formula if my table headers have different names?
Yes. Replace [@[Planned Tonnage]] and [@[Produced Tonnage]] with structured references matching your exact Excel Table column headers.
Why is Excel not filling the formula down the whole table column?
Enter the formula in the first data row of the table and press Enter. If automatic calculated columns are disabled, select the formula cell and drag or copy it down through the remaining rows.




