Table Formulas and Calculations

Sunday, September 22, 2024

6:55 AM

# Add, Delete, Highlight, and Recalculate Formula

OneNote lets you insert an Excel table on a page or convert a table to an Excel object. This is convenient if you want complicated formulas and charts... and you have Excel installed! But what if you don't?

OneMore adds Excel-like formula functionality to native OneNote tables. You can apply a formula to one or more selected cells in a table. A formula can consist of basic mathematical operators, parenthesis, and most math functions such as abs, sum, average, sin, etc.

Formula Dialog |

- Select the cell or cells into which you want to add a formula; they must be linear and contiguous, meaning in the same row or in the same column.
- Select the Add Formula command, F5. The Formula dialog is displayed showing the names of the selected cells: A1, A2, A3, etc.
- Enter the formula. As you type, OneMore validates the syntax in real-time, showing whether the formula is valid or invalid. Only when it is valid will the OK button be enabled.
- Choose the format of the result: Number, Currency, or Percentage.
- Choose whether you want to tag the cell with a lightning bolt to make it easy to identify cells with formulas in them.
- Click OK.

Formula processing is not recursive across cells. This means that if cell A1 has a formula "A2+1" and cell A2 has a formula "1+1", then when A1 is calculated, it will not force A2 to be recalculated. Instead, each cell is calculated in order, top-down and left-to-right across the table.

The Recalculate command, Shift + F5, will recalculate all formulas in the selected table(s).

The Highlight command will select all cells on the page containing formulas so you know where you put them.

The Delete command will remove a formula from the selected cell(s) but retain the values displayed in those cell.

## Relative Cell Ranges for Individual Columns or Rows

In spreadsheet-like tables containing data summarized by mathematical expressions, it is quite common to add or remove data in the table. Since OneNote tables are not as dynamic as an Excel spreadsheet, this means that a hard-coded formula in the last row of a table may lose context when the number of rows above it are changed. For example, a formula in cell A10 may break after row 9 is deleted.

OneMore solves this by introducing the idea of relative cell ranges. The cell function can be used to specify a cell relative to the cell containing the formula. This functions allows both column offset and row offset, as well as forward looking relative references. The full syntax of the cell function is

cell(colOffset, rowOffset)

Example: To add a reverse-looking summary cell to the bottom of the first column of a 10 row table, the formula sum(A1,cell(0,-1)) will total all cells in the column from the first row (A1), down to the row just prior to the formula cell (A9).

Example: To add a forward-looking summary cell to the top of the first column of a 10 row table in cell A1, the formula sum(A2, cell(0, tablerows-1)) will total all cells in the column from the second row (A2), down to the cell in the last row of the table (A10); note that rowOffset parameter still needs to be expressed as an offset from the current cell, hence tablerows-1, which is (A1 + tablerows - 1 = A1 + 10 - 1 = A1 + 9 = A10)

Both tablerows and tablecols are provided as pre-defined variables for use within table formulas.

### Auto-Incremented Column References

If you use cell references in your formula and you've selected more than one cell then OneMore will automatically increment the references relative to each seleted cell. For example, if you select cells A10, B10, and C10 and enter the formula sum(A1:A9) then that will apply to A10, sum(B1:B9) will apply to B10, and sum(C1:C9) will apply to C10.

## Functions

Available functions include abs, acos, arccos, arcsin, arctan, asin, atan, atan2, average, ceil, ceiling, cos, cosh, exp, floor, log, log10, max, median, min, mode, pow, range, rem, root, round, sign, sin, sinh, sqrt, stdev, sum, tan, tanh, trunc, truncate, and variance.

Additionally, the following special functions are included.

### countif(range, criteria)

Counts the number of values in the given range that match the specified criteria. The range should be specified in similar to A2:A7. The criteria can be a numeric value such as 123 or 45.66; it can be a boolean, true or false, in which case it will look for checkbox tags in each cell and will ignore all other content in the cells; or it can be a simple string match such as abc (do not include quotes). Additionally, three operators are allowed for numeric and string matches: <, >, and !. The countif function will ignore empty cells.

The countif function is often used along with the cell function, for example

countif(A1:cell(0,-1), < 123)

would allow a function in the last row of the A column, that counts values less than 123 in the range A1..An

## Variables

The following variables are recognized by the OneMore formula parser and will be replaced with their know values when the formula is evaluated: e, phi, pi, tao, tablecols, and tablerows.

#omwiki #omcommands

© 2020 Steven M Cohn. All rights reserved.

Please consider a sponsorship or one-time donation to support ongoing development

Created with OneNote.