LibreOffice Calc Guide 12
LibreOffice Calc Guide 12
For statistical and mathematical purposes, Calc includes a variety of ways to round off numbers. If
you are a programmer, you may also be familiar with some of these methods. However, you do not
need to be a specialist to find some of these methods useful. You may want to round off for billing
purposes, or because decimal places do not translate well into the physical worldfor instance, if
the parts you need come in packages of 100, then the fact you only need 66 is irrelevant to you;
you need to round up for ordering. By learning the options for rounding up or down, you can make
your spreadsheets more immediately useful.
When you use a rounding function, you have two choices about how to set up your formulas. If you
choose, you can nest a calculation within one of the rounding functions. For instance, the formula
=ROUND((SUM(A1,A2)) adds the figures in cells A1 and A2, then rounds them off to the nearest
whole number. However, even though you do not need to work with exact figures every day, you
may still want to refer to them occasionally. If that is the case, then you are probably better off
separating the two functions, placing =SUM(A1,A2) in cell A3, and =ROUND (A3) in A4, and clearly
labeling each function.
Rounding methods
The most basic function for rounding numbers in Calc is ROUND. This function will round off a
number according to the usual rules of symmetric arithmetic rounding: a decimal value of .4 or less
gets rounded down, while one of .5 or more gets rounded up. However, at times, you may not want
to follow these rules. For instance, if you are one of those contractors who bills a full hour for any
fraction of an hour you work, you would want to always round up so you did not lose any money.
Conversely, you might choose to round down to give a slight discount to a long-established
customer. In these cases, you might prefer to use ROUNDUP or ROUNDDOWN, which, as their
names suggest, round a number to the nearest integer above or below it.
All three of these functions require the single argument of numberthe cell or number to be
rounded. Used with only this argument, all three functions round to the nearest whole number, so
that 46.5 would round to 47 with ROUND or ROUNDUP and 46 with ROUNDDOWN. However, if
you use the optional count argument, you can specify the number of decimal places to include. For
instance, if number was set to 1, then 48.65 would round to 48.7 with ROUND or ROUNDUP and
to 48.6 with ROUNDDOWN.
As an alternative to ROUNDDOWN when working with decimals, you can use TRUNC (short for
truncate). It takes exactly the same arguments as ROUNDDOWN, so which function you use is a
matter of choice. If you are not working with decimals, you might choose to use INT (short for
integer), which takes only the number argument.
Another option is the ODD and EVEN pair of functions. ODD rounds up to the nearest odd number
if what is entered in the number argument is a positive number, and rounds down if it is a negative
number, while EVEN does the same for an even number.
Further options are the CEILING and FLOOR functions. As you can guess from the names,
CEILING rounds up and FLOOR rounds down. For both functions, the number that they round to is
determined by the closest multiple of the number that you enter as the significance argument which
is above or below the value being tested. For instance, if your business insurance is billed by the
work week, the fact that you were only open three days one week would be irrelevant to your
costs; you would still be charged for an entire week, and therefore might want to use CEILING in
your monthly expenses.
If cell E1 contains the value 46.7, =CEILING(E1,7) will return the value 49, this being the closest
multiple of 7 above the value.
Conversely, if you are building customized computers and completed 4.5 in a day, your client
would only be interested in the number ready to ship, so you might use FLOOR in a report of your
progress.
Regular expression searches within functions are always case insensitive, irrespective of the
setting of the Case sensitive checkbox on the dialog in Figure 168so red and ROD will always
be matched in the above example. This case-insensitivity also applies to the regular expression
structures ([:lower:]) and ([:upper:]), which match characters irrespective of case.
Regular expressions will not work in simple comparisons. For example: A1="r.d" will always return
FALSE if A1 contains red, even if regular expressions are enabled. It will only return TRUE if A1
contains r.d (r then a dot then d). If you wish to test using regular expressions, try the COUNTIF
function: COUNTIF(A1,"r.d") will return 1 or 0, interpreted as TRUE or FALSE in formulas like
=IF(COUNTIF(A1,"r.d"),"hooray","boo").
Advanced functions
As is common with other spreadsheet programs, LibreOffice Calc can be enhanced by user-
defined functions or add-ins. Setting up user-defined functions can be done either by using the
Basic IDE or by writing separate add-ins or extensions.
The basics of writing and running macros is covered in Chapter 12, Calc Macros. Macros can be
linked to menus or toolbars for ease of operation or stored in template modules to make the
functions available in other documents.
Calc Add-ins are specialized office extensions which can extend the functionality of LibreOffice with
new built-in Calc functions. Writing Add-ins requires knowledge of the C++ language, the
LibreOffice SDK, and is for experienced programmers. A number of extensions for Calc have been
written and these can be found on the extensions site at http://extensions.libreoffice.org/. Refer to
Chapter 14, Setting up and Customizing Calc, for more details.
Database preconditions
The first thing needed to work with the Pivot Table is a list of raw data, similar to a database table,
consisting of rows (data sets) and columns (data fields). The field names are in the first row above
the list.
The data source could be an external file or database. For the simplest case, where data is
contained in a Calc spreadsheet, Calc offers sorting functions that do not require the Pivot Table.
For processing data in lists, the program needs to know where in the spreadsheet the table is. The
table can be anywhere in the sheet, in any position. A spreadsheet can contains several unrelated
tables.
Calc recognizes your lists automatically. It uses the following logic: Starting from the cell you have
selected (which must be within the list), Calc checks the surrounding cells in all 4 directions (left,
right, above, below). The border is recognized if the program discovers an empty row or column, or
if it hits the left or upper border of the spreadsheet.
This means that the described functions can only work correctly if there are no empty rows or
columns in your list. Avoid empty lines (for example for formatting). You can format your list by
using cell formats.
If you select more than one single cell before you start sorting, filtering, or calling the Pivot Table,
then the automatic list recognition is switched off. Calc assumes that the list matches exactly the
cells you have selected.
Rule For sorting, filtering, or using the Pivot Table, always select only one cell.
A relatively common source of errors is to inadvertently declare a list by mistake and then to sort
that list. If you select multiple cellsfor example, a whole columnthen the sorting mixes up the
data that should be together in one row.
In addition to these formal aspects, the logical structure of your table is also very important.
Calc lists must have the normal form; that is, they must have a simple linear
Rule structure.
When entering the data, do not add outlines, groups, or summaries. Here are some mistakes
commonly made by inexperienced spreadsheet users:
1) You made several unnecessary sheets; for example, a sheet for each group of articles. In
this case, analyses are then possible only within each group.
2) In a Sales list, instead of only one column for the amount, you made a column for the
amounts for each employee. In this case, the system will have difficulty grouping data from
the various columns together. Thus, an analysis with the Pivot Table would no longer be
Data sources
At this time, the possible data sources for the Pivot Table are a Calc spreadsheet or an external
data source that is registered in LibreOffice.
Calc spreadsheet
Analyzing a list in a Calc spreadsheet is the simplest and most often used case. Lists might be
updated regularly, or the data might be imported from a different application.
The behavior of Calc while inserting data from a different application depends on the format of the
data. If the data is in a common spreadsheet format, it is copied directly into Calc. However, if the
data is in plain text format, the Text Import dialog (Figure 171) appears after you select the file
containing the data; see Chapter 1, Introducing Calc, for more more information about this dialog.
Figure 171: Selecting the source data for the Pivot Table
Basic layout
In the Pivot Table dialog (Figure 172) are four white areas that show the layout of the result. Beside
these white areas are buttons with the names of the fields in your data source. To choose a layout,
drag and drop the field buttons into the white areas.
The Data Fields area in the middle must contain at least one field. Advanced users can use more
than one field here. For the Data Field an aggregate function is used. For example, if you move the
sales field into the Data Fields area, it appears there as Sum sales.
Row Fields and Column Fields indicate from which groups the result will be sorted. Often more
than one field is used at a time to get partial sums for rows or columns. The order of the fields
gives the order of the sums from overall to specific.
For example, if you drag region and employee into the Row Fields area, the sum will be divided
into the employees. Within the employees will be the listing for the different regions (see Figure
173).
Figure 173: Pivot Table field order for analysis, and resulting layout in pivot table
Fields that are placed into the Page Fields area appear in the result above as a drop down list. The
summary in your result takes only that part of your base data into account that you have selected.
For example, if you use employee as a Page Field, you can filter the result shown for each
employee.
To remove a field from the white layout area, just drag it past the border and drop it (the cursor will
change to a crossed symbol), or select it and click the Remove button.
More options
To expand the Pivot Table dialog and show more options, click More.
Selection from
Shows the sheet name and the range of cells used for the Pivot Table.
Results to
Results to defines where your result will be shown. Setting Results to as undefined and
then entering a cell reference tells the Pivot Table where to show the results.1 An error dialog
is displayed if you fail to enter a cell reference. Selecting Results to as - new sheet adds a
new sheet to the spreadsheet file and places the results there. The new sheet is named using
the format Pivot Table_sheetname_X; where X is the number of the table created, 1 for first, 2
for second and so on. For the source shown in Figure 3, the new sheet for the first table
produced would be named Pivot Table_sheetname_1. Each new sheet is inserted next to the
source sheet.
Identify categories
With this option selected, if the source data has missing entries in a list and does not meet the
recommended data structure (see Figure 175), the Pivot Table adds it to the listed category
above it. If this option is not chosen, then the Pivot Table inserts (empty) (see Figure 177).
1 In this case the word - undefined is misleading because the output position is in fact defined.
Add filter
Use this option to add or hide the cell labeled Filter above the Pivot Table results. This cell is a
convenient button for additional filtering options within the Pivot Table.
In the Displayed value section, you can choose other possibilities for analysis by using the
aggregate function. Depending on the setting for Type, you may have to choose definitions for
Base field and Base item.
The table below lists the possible types of displayed value and associated base field and item,
together with a note on usage.
Figure 180: Original Pivot Table (top) and a Difference from example (below)
Figure 184: Division of the regions for employees (two row fields) without subtotals
You can remove a column, row, or page field from the Pivot Table by clicking on it and dragging it
out of the table. The cursor changes to that shown in Figure 191. A field removed in error cannot
be recovered, and it is necessary to return to the Pivot Table to replace it.
Before you can group, you have to produce a Pivot Table with ungrouped data. The
time needed for creating a Pivot Table depends mostly on the number of columns
Note and rows and not on the size of the basic data. Through grouping you can produce
the Pivot Table with a small number of rows and columns. The Pivot Table can
contain a lot of categories, depending on your data source.
You can select several non-contiguous cells in one step by pressing and holding the
Tip Control key while left-clicking with the mouse.
Given the input data shown in Figure 195, execute the Pivot Table with Department in the Row
Field and Sum (Sick Days) in the Data Field. The output should look like that in Figure 196. With
the mouse, select the Departments Accounting, Purchasing and Sales.
You can change the default names for the groups and the newly created group field by editing the
name in the input field (for example changing 'Group2' to 'Technical'). The Pivot Table will
remember these settings, even if you change the layout later on. For the following pictures, the
dialog was called again (right-click, Edit Layout) and by selecting the icon Department 2, then
Options, and finally from the preferences menu Automatic was selected. This generated the
partial sum results shown in Figure 199. Double clicking Group 1 and Technical collapses the
entries, as shown in Figure 200.