# Difference between revisions of "Documentation/OOo3 User Guides/Calc Guide/Using functions"

(added Link to function list) |
(Fixed paragraph comparing functions with existing operators.) |
||

Line 9: | Line 9: | ||

Typically, the name of a function is an abbreviated description of what the function does. For instance, the FV function gives the future value of an investment, while BIN2HEX converts a binary number to a hexadecimal number. By tradition, functions are entered entirely in upper case letters, although Calc will read them correctly if they are in lower or mixed case, too. | Typically, the name of a function is an abbreviated description of what the function does. For instance, the FV function gives the future value of an investment, while BIN2HEX converts a binary number to a hexadecimal number. By tradition, functions are entered entirely in upper case letters, although Calc will read them correctly if they are in lower or mixed case, too. | ||

− | A few basic functions are | + | A few basic functions are somewhat similar to operators. Examples: |

+ | :"+", this operator will add two numbers together for a result. SUM() on the other hand will add a contiguous '''''range''''' of numbers together. | ||

+ | :"*", this operator will multiply to numbers together for a result. PRODUCT() does the same for multiplying, that SUM() does for adding. | ||

− | Each function has a number of ''arguments'' used in the calculations. These arguments may or may not have their own name. Your | + | Each function has a number of ''arguments'' used in the calculations. These arguments may or may not have their own name. Your task is to enter the arguments needed to run the function. In some cases, the arguments have pre-defined choices, and you may need to refer to the online help or Appendix B (Description of Functions) in this book to understand them. More often, however, an argument is a value that you enter manually, or one already entered in a cell or range of cells on the spreadsheet. In Calc, you can enter values from other cells by typing in their name or range, or—unlike the case in some spreadsheets—by selecting cells with the mouse. Should the values in the cells change, the result of the function will be automatically updated. |

Strictly speaking, when all the arguments are entered and a function is ready to run, it becomes a ''formula''. These terms are sometimes used interchangeably, but the distinction is worth preserving, because a formula can use functions as an argument. | Strictly speaking, when all the arguments are entered and a function is ready to run, it becomes a ''formula''. These terms are sometimes used interchangeably, but the distinction is worth preserving, because a formula can use functions as an argument. |

## Revision as of 04:32, 14 September 2009

Calc includes over 350 functions to help you analyze and reference data. Many of these functions are for use with numbers, but many others are used with dates and times, or even text. A function may be as simple as adding two numbers together, or finding the average of a list of numbers. Alternatively, it may be as complex as calculating the standard deviation of a sample, or a hyperbolic tangent of a number. See a list of all functions in **functions listed by category**.

Typically, the name of a function is an abbreviated description of what the function does. For instance, the FV function gives the future value of an investment, while BIN2HEX converts a binary number to a hexadecimal number. By tradition, functions are entered entirely in upper case letters, although Calc will read them correctly if they are in lower or mixed case, too.

A few basic functions are somewhat similar to operators. Examples:

- "+", this operator will add two numbers together for a result. SUM() on the other hand will add a contiguous
of numbers together.**range** - "*", this operator will multiply to numbers together for a result. PRODUCT() does the same for multiplying, that SUM() does for adding.

Each function has a number of *arguments* used in the calculations. These arguments may or may not have their own name. Your task is to enter the arguments needed to run the function. In some cases, the arguments have pre-defined choices, and you may need to refer to the online help or Appendix B (Description of Functions) in this book to understand them. More often, however, an argument is a value that you enter manually, or one already entered in a cell or range of cells on the spreadsheet. In Calc, you can enter values from other cells by typing in their name or range, or—unlike the case in some spreadsheets—by selecting cells with the mouse. Should the values in the cells change, the result of the function will be automatically updated.

Strictly speaking, when all the arguments are entered and a function is ready to run, it becomes a *formula*. These terms are sometimes used interchangeably, but the distinction is worth preserving, because a formula can use functions as an argument.

For compatibility, functions and their arguments in Calc have almost identical names to their counterparts in Microsoft Excel. However, both Excel and Calc have functions that the other lacks. Occasionally, too, functions with the same names in Calc and Excel have different arguments, or slightly different names for the same argument—neither of which can be imported to the other. However, perhaps nine-tenths of functions can be imported between Calc and Excel without any problems.

## Understanding the structure of functions

Except for simple functions such as + or *, all functions have a similar structure. If you use the right tool for entering a function, you can escape learning this structure, but it is still worth knowing for troubleshooting.

To give a typical example, the structure of a function to find cells that match entered search criteria is:

= DCOUNT (Database;Database field;Search_criteria)

Like most functions, this one starts with an equal sign. It is followed by DCOUNT, the name of the function. After the name of the function comes its arguments. All arguments are required, unless specifically listed as optional.

Arguments are added within the brackets (parentheses) and separated by semicolons, with no space between the arguments and the semicolons. Many arguments are a number. A Calc function can take up to thirty numbers as an argument. That may not sound like much at first. However, when you realize that the number can be not only a number or a single cell, but also an array or range of cells that contain several or even hundreds of cells, then the apparent limitation vanishes.

Other arguments may be a column label, a mathematical constant, or a value unique to that function.

Depending on the function, arguments may have to be entered with straight quotation marks. However, this requirement is not consistent. Otherwise similar formulas may differ only in this requirement, and no simple rule tells you which is which. You simply have to know or check the requirements in the online help.

The only exception to these structural rules are basic arithmetical functions entered with symbols. For example, instead of entering =SUM(2;3), you can enter =2+3.

## Advanced structure

As well as being used on its own, a function can be an argument in a larger formula. A formula, however, is limited by the fact that it can only do one function at a time. You need to make sure that functions are done in the right order if the formula is going to work.

To help set the order for functions in a multiple-function formula, you use parentheses within parentheses. When the formula is run, Calc does the innermost function first, then works outwards. For example, in the simple calculation =2+(5*7), Calc multiples 5 by 7 first. Only then is 2 added to the result to get 37.

The placement of functions within sets of parentheses is called *nesting*. Basically, nesting reduces a function that could run on its own to an argument in the formula. For example, in =2+(5*7), the formula (5*7) is nested within the larger formula of =2+(5*7). In other words, the nested function becomes an argument of another function.

This relation is more obvious when doing a calculation using a function with a name. For all purposes,

=SUM(2;PRODUCT(5;7))

is the same formula as =2+(5*7). However, when SUM and PRODUCT are used, then the relation is clearer. The fact that the PRODUCT function comes after a semicolon and in a set of parentheses for the SUM function makes it clear that PRODUCT is an argument for SUM. In addition, the fact that the inner pair of parentheses is around (5;7) makes clear that this operation is done before the one defined by the outer pair of parentheses.

To get an idea of what nested functions can do, imagine that you are designing a self-directed learning module. During the module, students do three quizzes, and enter the results in cells A1, A2, and A3. In A4, you can create a nested formula that begins by averaging the results of the quizzes with the formula =AVERAGE(A1:A3). The formula then uses the IF function to give the student feedback that depends upon the average grade on the quizzes. The entire formula would read:

=IF(AVERAGE(A1:A3) >85; "Congratulations! You are ready to advance to the next module"; "Failed. Please review the material again. If necessary, contact your instructor for help")

Depending on the average, the student would receive the message for either congratulations or failure.

Notice that the nested formula for the average does not require its own equal sign. The one at the start of the equation is enough for both formulas.

If you are new to spreadsheets, the best way to think of functions is as a scripting language. We've used simple examples to explain more clearly, but, through nesting of functions, a Calc formula can quickly become complex.

Content on this page is licensed under the Creative Common Attribution 3.0 license (CC-BY). |