6.2. Formulas

Formulas are the key to making a powerful spreadsheet. A formula can perform calculations on almost anything, including single numbers, cells of data ("cell references"), ranges of cells, arrays of cells, and more.

6.2.1. Syntax

Formulas are distinguished from regular data by an equals sign, '=,' as the first character. Everything following a '=' is evaluated as a formula, not a string or a number.

TipAlternate Beginnings for Formulas
 

To accomodate those more familiar with Lotus spreadsheets, Gnumeric recognizes the at symbol as the beginning of a formula. The plus and minus characters (+ and -) may also start formulas that involve calculation, but when used in front of a single number indicate the sign of the number.

The simplest formulas just use the standard math operator and symbols. Addition, subtraction, multiplication, and division are represented by +, -, *, and /, just as you would expect. +,- can be placed in front of numbers to indicate sign, as well.

Example 6-1. Examples of standard operators

	=5+5            returns 10.
	
	=5-4            returns 1.
	
	=-5             returns -5.
	
	=5*5            returns 25.
	
	=(5*5)+11       returns 36.
	
	=(5*5)+(49/7)    returns 32.
      

6.2.2. Using Functions

Most of the standard math, business, statistical, and scientific calculations are implemented in terms of functions. Functions are in the form of:

Example 6-2. Basic Function syntax

	=FUNCTION(ARGUMENTS)
      

While the documentation generally refers to functions and to cells in capital letters, their use is not actually case sensitive.

Example 6-3. Some examples of function syntax

	    =SUM(A1,A2,A4,B5)
	    
            =AVERAGE(A1:A16)
	    
            =EXP(1)
	    
	    =PI()
	    
            =MIN(A1,A2,B6)
	  

Where a function takes multiple arguments such as the SUM example, the number of arguments effectively unlimited.

6.2.3. Names

Names help to simplify complex formulae. A name is assinged to a formula which will be evaluated when it is referred to in another formula. Names are particularly useful for labeling cell ranges.

Example 6-4. Examples of name usage

If DataBase is defined as '$A$1:$B$500' and E_Constant is defined as 2.71828182845 then we can have:

	    =VLOOKUP (C1, "gnu", DataBase, 2, 0)

	    =LN(E_Constant)

	    =SUM(DataBase, E_Constant)
	  

Names are defined using the Insert Name dialog. This allows manipulation of all the names in the related workbook. A name is restrained from taking that of a function, since this would cause confusion.

In addition to the names you define there are built in names:

6.2.4. Array Formulas

It is periodically useful or necessary to have an expression return a matrix rather than a single value. The first example most people think of are matrix operations such as multiplication, transpose, and inverse. A less obvious usage is for data retrieval routines (databases, realtime data-feeds) or functions with vector results (yield curve calculations).

Example 6-5. Entering an Array Formula

An array formula is currently entered by selecting the single range in which to store the result, entering the array formula, and hitting the magic combination, Ctrl-Shift-Enter.

The result is displayed as :

	={FUNCTION(ARGUMENTS)}(num_rows, num_cols)[row number][col number]