Performing Math Calculations in Word Tables
A need sometimes arises to perform a few simple math calculations in Word tables, which inevitably begs the question, "How do I do that?"
In Word's Table Layout tab, which displays when you place your cursor inside a table cell, you will see a Formula button and selecting it opens the Formulas dialog.
In the image above the Formula field is pre-filled with =SUM(LEFT), which is the math function for adding all values from the direction specified.
In this case it is cells to the left of the summary cell. When using the SUM function, it is important to know that cells holding non-numeric data or are blank, stop the automatic search for more data.
For example below, the shaded cell holds the =SUM(LEFT) formula. The calculated value is 4, while if the second cell in the row had held a value of 0, the calculated value of the row would have been 6.
The math function SUM is one of many that are available. If you click the pull-down menu in the Paste function box on the Formula dialog, you can see them all.
For now, I'll just be discussing the SUM function and things you can do with it, which is the most commonly used, and I'll use the example below to explain it.
The example shows a table with SUM function fields in the shaded cells. To make them work the table needed some special formatting.
The red arrows are pointing to what looks like bolded row border lines, but in fact they are blank table rows that are only 0.01 inches in height. You set row height from the Properties function of the Table Layout tab. Since the rows are blank, this allows the SUM function, particularly the one adding up Services, to process only the two cells in the example.
To get the SUM function to work for the Grand Total, bookmarks surround the formula field that calculate the subtotals. Showing you what the coding of the SUM function formula field looks like, should help you see how to construct one for yourself. The field coding also includes the choice for displaying the numbers in U.S. dollar formatting.
I've tried to be careful and use the proper terminology of Fields, Formulas, and Functions and I want to explain why. What you are seeing in the image above is the coding of a Word Field, and I have my Word preference set to show Field shading. A Formula is one of the many types of automation Fields that you can use in your documents. Within a Formula Field, SUM is one of many mathematical Functions that you can use. With all of that said, what you are looking at is the Field coding for a SUM Function Formula.
Curly brackets delineate Fields. They include special hidden coding and if typed manually, only use a keystroke combination of Control+F9 to insert them. As mentioned earlier, the SUM function formula includes a directive from where it is supposed to get the data. For the Subtotals, we are telling it to use the data cells that are ABOVE this cell. For the Grand Total we are telling it to get the data to sum from the Fields bookmarked as Materials and Services. If we had more bookmarked fields, we would just insert a comma and add the name of the bookmark.
In each of the formulas notice the \# symbols followed by an empty space. These tell the formula calculator that what follows is formatting code for the data. Our formatting is for U.S. dollar notation, the largest number possible is $9,999.99 and smallest positive number is $0.00 with negative numbers displaying within parenthesis and leading zeros suppressed.
With these Field Formulas in place, Bookmarks surrounding the Subtotal Formula Fields, and proper Blank or Non-Numeric data cell delimiters also in place… when we add a new data row to our table and press F9 after selecting the table, all Formulas recalculate.