0% found this document useful (0 votes)
21 views

Data Processing Using Advanced Tools

This document discusses tools for data processing using advanced functions in spreadsheets: - It describes how to filter data using standard, auto, and advanced filters to display only relevant records. - Sorting is discussed as a way to arrange cells by specified criteria to organize the data. - Pivot tables and macros are also mentioned as tools for data analysis and customization.

Uploaded by

vishminu95
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Data Processing Using Advanced Tools

This document discusses tools for data processing using advanced functions in spreadsheets: - It describes how to filter data using standard, auto, and advanced filters to display only relevant records. - Sorting is discussed as a way to arrange cells by specified criteria to organize the data. - Pivot tables and macros are also mentioned as tools for data analysis and customization.

Uploaded by

vishminu95
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

DATA PROCESSING USING ADVANCED

TOOLS

Data Processing using advanced tools


 Data Filtering

 Data Sorting

 Pivot Table

 Data Analysis

 Working with Macro

Filtering
A filter is a list of conditions that each entry has to meet to be displayed. Calc provides three
types of filter:
Standard – specifies the logical conditions to filter your data.

Chapter 2 Entering, Editing, and Formatting Data 72

Data Processing using advanced tools


AutoFilter – filters data according to a specific value or string. Automatically filters the
selected cell range and creates one-row list boxes where you can choose the items
that you want to display.
Advanced – uses filter criteria from specified cells.

Applying a standard filter


A standard filter is more complex than AutoFilter. You can set as many as eight conditions as
a filter, combining them with the operators AND or OR. Standard filters are mostly useful for
numbers, although a few of the conditional operators can also be used for text.
Select a cell range in your spreadsheet.
Go to Data > Filter > Standard Filter on the menu bar to open the Standard Filter
dialog (Figure 52).
Specify the filter criteria and filtering options that you want to use.
Click OK to carry out standard filtering and close the dialog. Any records that match
the filter criteria and options that you specified are shown.

Figure 52: Standard Filter dialog

The filter criteria used in standard filtering defines a filter by indicating the type of line, the name
of the field, a logical condition and a value or a combination of arguments.
Operator – for the following arguments, you can choose between the logical
operators AND / OR.
Field name – specifies the field names from the current table to set them in the
argument. You will see the column identifiers if no text is available for the field names.
Condition – specifies the comparative operators through which the entries in the
Field name and Value fields can be linked.
Value – specifies a value to filter the field. The Value list box contains all possible values
for the specified Field name. Select a value to be used in the filter, including Empty and
Not Empty entries.
Case sensitive – distinguishes between uppercase and lowercase letters when filtering
the data.

Chapter 2 Entering, Editing, and Formatting Data 73

Data Processing using advanced tools


Range contains column labels – includes the column labels in the first row of a
cell range.
Copy results to – select the check box and then select the cell range where you want
to display the filter results. You can also select a named range from the list.
Regular expression – select to use wildcards in the filter definition. See LibreOffice
Help for a list of the regular expressions that LibreOffice supports. If selected, you can
use regular expressions in the Value field if the Condition list box is set to '=' EQUAL or
'<>' UNEQUAL. This also applies to the respective cells that you reference for an
advanced filter.
No duplication – excludes duplicate rows from the list of filtered data.
Keep filter criteria – select Copy results to and then specify the destination range
where you want to display the filtered data. If this box is checked, the destination range
remains linked to the source range. You must have defined the source range under Data
> Define range as a database range. You can also reapply the defined filter at any time
by clicking into the source range and then go to Data > Refresh Range.

Figure 53: AutoFilter example

Applying an AutoFilter
An AutoFilter adds a drop-down list to the top row of one or more data columns which lets you select
the rows to be displayed. The list includes every unique entry in the selected cells sorted into lexical
order (see http://sheepsystems.com/bookdog/HelpBook/LexicalOrder.html for an

Chapter 2 Entering, Editing, and Formatting Data 74

Data Processing using advanced tools


explanation of lexical order). AutoFilter can be used on multiple sheets without first defining
a database range.
Click in a cell range on your spreadsheet. If you want to apply multiple AutoFilters to
the same sheet, you must first define database ranges, then apply the AutoFilters to
the database ranges.
Go to Data > Filter > AutoFilter on the menu bar. An arrow button is added to the head
of each column in the database range.
Click the arrow or small triangle in the column that contains the value or string that
you want to set as the filter criteria (shown in Figure 53).
Select the value or string that you want to use as the filter criteria. The records that
match the filter criteria that you selected are then shown.

Applying an advanced filter


An advanced filter has a structure similar to a standard filter. The difference is that the Advanced
Filter arguments are not entered in a dialog. Instead, filters can be entered in a blank area of a
spreadsheet, then referenced by the filter dialog to apply the filters.
Select a cell range in your spreadsheet.
Go to Data > Filter > Advanced Filter on the menu bar to open the Advanced Filter
dialog (Figure 54).
In Read filter criteria from, select the named range, or enter the cell range that contains
the filter criteria that you want to use
Click OK to carry out advanced filtering and close the dialog. Any records that match
the filter criteria and options that you specified are shown.

Figure 54: Advanced Filter dialog

The options for advanced filtering are the same as those used for standard
Note filtering, see “Applying a standard filter” on page 73 for more information.

Chapter 2 Entering, Editing, and Formatting Data 75

Data Processing using advanced tools


When a cell is moved during a sort operation, external references to that cell are not
updated. If a cell that contains a relative reference to another cell is moved, the
Caution reference is relative to the new position when sorting is finished. Know the
behavior of references during sorting and do not be alarmed; this is almost
always what you want—because the reference is to the right or left in the same
row. Also, we have not found a spreadsheet program that exhibits a different
behavior for references while sorting.

Figure 306: Set sort options

Filters
Use filters to limit the visible rows in a spreadsheet. Generic filters, common to all sorts of data
manipulations, are automatically provided by the auto filter capability. You can also define your
own filters.

After applying a filter, some rows are visible and some rows are not. If you select
Caution multiple rows in one operation, you will also select the invisible rows
contained between the selected visible rows. Operations, such as delete, act
on all of the selected rows. To avoid this problem, you must individually select
each of the filtered rows using the control key.

Chapter 13 Calc as a Simple Database 329

Data Processing using advanced tools


Sorting records
Sorting within Calc arranges the cells in a sheet using the sort criteria that you specify. Several
criteria can be used and a sort applies each criteria consecutively. Sorts are useful when you
are searching for a particular item and become even more useful after you have filtered data.
Also, sorting is useful when you add new information to a spreadsheet. When a spreadsheet is
long, it is usually easier to add new information at the bottom of the sheet, rather than adding
rows in their correct place. After you have added information, you can then sort the records to
update the spreadsheet.

Chapter 2 Entering, Editing, and Formatting Data 75

Data Processing using advanced tools


Sort dialog
To sort cells in a spreadsheet using the Sort dialog (Figure 55):
Select the cells to be sorted.
Go to Data > Sort on the menu bar to open the Sort dialog. Make sure the Sort
Criteria page is open.
Select the sort criteria from the drop-down lists. The selected lists are populated from
the selected cells.
Select either ascending order (A-Z, 1-9) or descending order (Z-A, 9-1).
Click OK and the sort is carried out on your spreadsheet.

Figure 55: Sort dialog – Sort Criteria page

Figure 56: Sort dialog – Options page

Sort options
On the Options page of the Sort dialog (Figure 56), you can set additional options:
Case Sensitivity – sorts first by uppercase letters and then by lowercase letters. For
Asian languages, special handling applies.

Chapter 2 Entering, Editing, and Formatting Data 76

Data Processing using advanced tools


For Asian languages, select Case Sensitivity to apply multi-level collation. With
multi-level collation, entries are first compared in their primitive forms with their

Note cases and diacritics ignored. If they evaluate as the same, their diacritics are
taken into account for the second-level comparison. If they still evaluate as the
same, their cases, character widths, and Japanese Kana difference are
considered for the third-level comparison.

Range contains column/row labels – omits the first row or the first column in the
selection from the sort. The Direction setting at the bottom of the dialog defines the
name and function of this check box.
Include formats – preserves the current cell formatting.
Enable natural sort – natural sorting is a sort algorithm that sorts string-prefixed numbers
based on the value of the numerical element in each sorted number, instead of the
traditional way of sorting them as ordinary strings. For instance, assume you have a
series of values such as, A1, A2, A3, A4, A5, A6, ..., A19, A20, A21. When you put these
values into a range of cells and run the sort, it will become A1, A11, A12, A13, ..., A19,
A2, A20, A21, A3, A4, A5, ..., A9. While this sorting behavior may make sense to those
who understand the underlying sorting mechanism, to the rest of the population it seems
completely bizarre, if not outright inconvenient. With natural sorting selected, values such
as the ones in the above example are sorted correctly, which improves the convenience
of sorting operations in general.
Copy sort results to – copies the sorted list to the cell range that you specify. Select a
named cell range where you want to display the sorted list, or enter a cell range in the
input box.
Custom sort order – select this option and then select the custom sort order that you
want to apply. To define a custom sort order, go to LibreOffice > Preferences >
LibreOffice Calc > Sort Lists.
Language – select the language for the sorting rules.
Options – select a sorting option for the language. For example, select the
"phonebook" option for German to include the umlaut special character in the sorting.
Top to Bottom (Sort Rows) – sorts rows by the values in the active columns of
the selected range.
Left to Right (Sort Columns) – sorts columns by the values in the active rows of
the selected range.

Quick sort
If the columns in your spreadsheet have a header with a text format, you can use a quick sort.
Select a cell or a cell range to be sorted.

Click the Sort Ascending or Sort Descending icons on the Standard toolbar.

Find and replace


Calc has two ways to find text within a document: the Find toolbar and the Find & Replace dialog.

Figure 57: Find toolbar

Chapter 2 Entering, Editing, and Formatting Data 77

Data Processing using advanced tools


Sorting
The sorting mechanism in a Calc document rearranges the data in the sheet. The first step in
sorting data is to select the data that you want to sort. To sort the data in Table 9, select the
cells from A1 to G16—if you include the column headers, indicate this in the sort dialog (see
Figure 306). Use Data > Sort to open the Sort dialog (see Figure 305). You can sort by up to
three columns or rows at a time.

Figure 305: Sort by the Name column

Click on the Options tab (see Figure 306) to set the sort options. Check the Range contains
column labels checkbox to prevent column headers from being sorted with the rest of the data.
The Sort by list box in Figure 305 displays the columns using the column headers if the Range
contains column labels checkbox in Figure 306 is checked. If the Range contains column
labels checkbox is not checked, however, then the columns are identified by their column name;
Column A, for example.
Normally, sorting the data causes the existing data to be replaced by the newly sorted data.
The Copy sort results to checkbox, however, causes the selected data to be left unchanged
and a copy of the sorted data is copied to the specified location. You can either directly enter a
target address (Sheet3.A1, for example) or select a predefined range.
Check the Custom sort order checkbox to sort based on a predefined list of values. To set
your own predefined lists, use Tools > Options > LibreOffice Calc > Sort Lists and then enter
your own sort lists. Predefined sort lists are useful for sorting lists of data that should not be
sorted alphabetically or numerically. For example, sorting days based on their name.

Chapter 13 Calc as a Simple Database 328

Data Processing using advanced tools


Data Processing using advanced tools
Introduction
Many requests for spreadsheet support are the result of using complicated formulas and solutions
to solve simple day-to-day problems. More efficient and effective solutions use the Pivot Table, a
tool for combining, comparing, and analyzing large amounts of data easily. Using Pivot Tables,
you can view different summaries of the source data, display the details of areas of interest, and
create reports, whether you are a beginner or an intermediate or advanced user.

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.

Rule No empty rows or empty columns are allowed within lists.

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 cells—for example, a whole column—then 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:
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.
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

Chapter 8 Using Pivot Tables 226

Data Processing using advanced tools


possible. All data must be entered into the same column for the Pivot Table to be able
to analyze it.
You entered the amounts in chronological order. At the end of each month, you made a
sum total. In this case, sorting the list for different criteria is not possible because the
Pivot Table will treat the sum totals the same as any other figure. Getting monthly results
is one of the very fast and easy features of the Pivot Table.

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 170: Text Import dialog


Calc is able to import data from a huge number of foreign data formats, such as other
spreadsheets (Excel, Lotus 1, 2, 3); from databases (like dBase); and from simple text files,
including CSV formats. However, in Calc, imported foreign data will not update automatically
if changes are made to the source file.
In LibreOffice Calc, you can use up to 1,048,576 rows.

Chapter 8 Using Pivot Tables 227

Data Processing using advanced tools


Registered data source
A registered data source is a connection to data held in a database outside of LibreOffice. When
using a registered data source, the data to be analyzed will not be saved in Calc; Calc always
uses the data from the original source. Calc is able to use many different data sources in addition
to databases that are created and maintained with LibreOffice Base. For more information, see
Chapter 10, Linking Calc Data.

Creating a Pivot Table


Create the Pivot Table using Data > Pivot Table > Create from the menu bar. If the list to be
analyzed is in a spreadsheet table, select only one cell within this list. Calc recognizes and
selects the list automatically for use with the Pivot Table (Figure 171).

Figure 171: Selecting the source data for the Pivot Table

The Pivot Table dialog


The function of the Pivot Table is managed in two places: first, in the Pivot Table dialog, and
second, through manipulations of the result in the spreadsheet. This section describes the dialog
in detail.

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.

Chapter 8 Using Pivot Tables 228

Data Processing using advanced tools


Figure 172: Pivot Table dialog

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.

Chapter 8 Using Pivot Tables 229

Data Processing using advanced tools


Figure 174: Expanded dialog of the Pivot Table

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
1
then entering a cell reference tells the Pivot Table where to show the results. 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.

Ignore empty rows


If the source data is not in the recommended form, this option tells the Pivot Table to
ignore empty rows.

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).

Figure 175: Example of data with missing entries in Column A


The option Identify categories ensures that in this example rows 3 and 4 are included for
the product Apples and that row 6 is included for Pears (see Figure 176).

Figure 176: Pivot Table result with Identify categories selected

In this case the word - undefined – is misleading because the output position is in fact defined.

Chapter 8 Using Pivot Tables 230

Data Processing using advanced tools


Without category recognition, the Pivot Table shows an (empty) category (Figure 177).

Figure 177: Pivot Table result without Identify categories selected


Logically, the behavior with category recognition is better. A list showing missing entries is
also less useful, because you cannot use functions such as sorting or filtering.

Total columns, Total rows


With these options you can decide if the Pivot Table shows an extra row with the sums of
each column, or if it adds on the very right a column with the sums of each row. In some
cases, an added total sum is meaningless, for example if your entries are accumulated or the
result of comparisons.

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.

Enable drill to details


With this option enabled, if you double-click on a single data cell, including a cell produced
from Total columns or Total rows, in the Pivot Table result, a new sheet opens giving a detailed
listing of the individual entry. If you double-click on a cell in either the Row Fields or the
Column Fields, then the Show Detail dialog open (see “Drilling (showing details)” on page 242).
Taking Figure 173 as an example, if a pivot table uses more than one field (region and
employee) and you double-click a left-most field (say, east), then this collapses the row,
combining the totals for employees for that field and displaying the totals for east. If this
function is disabled, the double-click will keep its usual edit function within a spreadsheet.

More settings for the fields: Field options


The options discussed in the previous section are valid for the Pivot Table in general. You can
also change settings for every field that you have added to the Pivot Table layout. To do
this,either select a field and click on the Options button in the Pivot Table dialog, or double-click
on the appropriate field.
The options available for fields when put into the Data Fields differ from those when put into
the Row, Column, and Page Fields of the Pivot Table.

Options for Data Fields


In the Options dialog of a Data Field, you can select the Sum function to accumulate the values
from your data source. While you will often use the sum function, other functions (like standard
distribution or a counting function) are also available. For example, the counting function can be
useful for non-numerical data fields.
On the Data Field dialog, click More to see the Displayed value section.

Chapter 8 Using Pivot Tables 231

Data Processing using advanced tools


Figure 178: Expanded dialog for a Data Field

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.

Figure 179: Example choices for Base field and item

The table below lists the possible types of displayed value and associated base field and
item, together with a note on usage.

Type Base field Base item Analysis


Normal — — Simple use of the chosen
aggregate function (for example,
sum).
Difference Selection of a field Selection of an The result is the difference
from from the data source element from the between the result of the Base field
of the Pivot Table selected base field and the Base item (for example,
(for example, (for example, Brigitte) sales volume of the employees
employee). against the sales volume of Brigitte;
see Figure 180).

Chapter 8 Using Pivot Tables 232

Data Processing using advanced tools


Type Base field Base item Analysis
% of Selection of a field Selection of an The result is a percentage ratio of
from the data element from the the value of the base field to the
source of the Pivot selected base field base item (for example, sales
Table (for example, (for example, Brigitte) result of the employee relative to
employee) the sales result of Brigitte; see
Figure 181).
Selection of a field Selection of an From each result, its reference
difference from the data source element from the value is subtracted, and the
from of the Pivot Table selected base field difference is divided by the
(for example, (for example. Brigitte) reference value (for example, sales
employee) of the employees as relative
difference from the sales of
Brigitte; see Figure 182).
Running Selection of a field — Each result is added to the sum of
total in from the data source the results for preceding items in
of the Pivot Table the base field, in the base field’s
(for example, date) sort order, and the total sum is
shown.
Results are always summed, even
if a different summary function was
used to get each result.
% of row — — The result is a percentage of the
value of the whole row (for
example, the row sum).
% of — — The result is a percentage of the
column total column value (for example, the
column sum).
% of total — — The result is a percentage of the
overall result (for example, the total
sum).
Index — — (Default result x total result) / (row
total x column total)

Figure 180: Original Pivot Table (top) and a Difference from example (below)

Chapter 8 Using Pivot Tables 233

Data Processing using advanced tools


Figure 181: Example of a % of analysis

Figure 182: Example of % difference from analysis

Options for Row and Column Fields


In the Options dialog for the Row or Column Fields, you can choose to show subtotals for each
category. Subtotals are deactivated by default. Subtotals are useful only if the values in one row
or column field can be divided into subtotals for another (sub)field.
Some examples are shown in the next three figures.

Figure 183: No subdivision with only one row or column field

Figure 184: Division of the regions for employees (two row fields) without subtotals

Chapter 8 Using Pivot Tables 234

Data Processing using advanced tools


Figure 185: Division of the regions for employees with subtotals (by region)
To calculate subtotals that can also be used for the data fields (see above), select the
Automatic option in the Subtotals section of the Data Field dialog.
You can choose the type of subtotal to use by selecting User-defined and then clicking the type
of subtotal you want to calculate from the list. Functions are only available when User-defined is
selected.

Figure 186: Preferences dialog of a row or column field

Chapter 8 Using Pivot Tables 235

Data Processing using advanced tools


Normally, the Pivot Table does not show a row or column for categories that have no entries in
the underlying database. By choosing the Show items with no data option, you can force this.
For illustration purposes, the data was manipulated in such a way that the employee Brigitte
has no sales values for the category golfing.

Figure 187: Default setting

Figure 188: Setting “Show Items with no data”

Options for Page Fields


The Options dialog for Page Fields is the same as for Row and Column fields, even though it
appears to be useless to have the same settings as described for the Row and Column fields. With
the flexibility of the Pivot Table, you can switch the different fields between pages, columns, or
rows. The fields keep the settings that you made for them. The Page Field has the same
properties as a Row or Column field. These settings only take effect when you use the field not as
a Page Field but as Row or Column field.

Working with the results of the Pivot Table


As mentioned above, the Pivot Table dialog is very flexible. A Pivot Table can be totally
restructured with only a few mouse clicks. Some functions of the Pivot Table dialog can only be
used with the Pivot Table.

Changing the layout


The layout of the Pivot Table can be changed quickly and easily by using drag-and-drop. With the
Pivot Table open, fields can be dragged around from row, column, page and the Data Fields areas to
any position you want to put them, and then dropped. Unused fields can also be added, and fields
removed in error can be replaced by dragging and dropping them into the positions required.
Some manipulation can also be carried out in the pivot table view. Within the results table of
the Pivot Table, move one of the page, column, or row fields to a different position. The cursor
will change shape from its starting shape (horizontal or vertical block on the arrow head) to the
opposite if moving to a different field, such as from row to column, and it is OK to drop.

Chapter 8 Using Pivot Tables 236

Data Processing using advanced tools


Figure 189: Drag a column field. Note Figure 190: Drag a row field. Note the
the cursor shape cursor shape

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.

Figure 191: Field dragged out


of the Pivot Table

Grouping rows or columns


For many analyses or summaries, the categories have to be grouped. You can merge the results
in classes. You can only carry out grouping on an ungrouped Pivot Table.
You can access grouping by selecting Data > Group and Outline > Group from the menu bar, or
by pressing F12 after selecting the correct cell area. The type of values that have to be grouped is
what mainly determines how the grouping function works. You need to distinguish between scalar
values, or other values, such as text, that you want grouped.

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.

Grouping of categories with scalar values


For grouping scalar values, select a single cell in the row or column of the category to be grouped.
Choose Data > Group and Outline > Group from the menu bar or press F12; you get the
Grouping dialog shown in Figure 192.
You can define in which value range (start/end) the grouping should take place. The default
setting is the whole range, from the smallest to the largest value. In the field Group by, you can
enter the class size, also known as the interval size (in the example shown in Figures 193 and
194, groups of 10 km/h each).

Chapter 8 Using Pivot Tables 237

Data Processing using advanced tools


Figure 192: Grouping dialog with scalar categories

Figure 194: Pivot Table with


grouping (classes of 10 km/h each)
Figure 193: Pivot Table without grouping
(frequency of the km/h values of a radar control)

Grouping without automatic creation of intervals


Categories containing text fields cannot create intervals. You can define for each field (for
example, Department) which values you want to put together in one group.
With more than one cell selected, choose Data > Group and Outline > Group from the menu
bar, or press F12, to group those cells. See Figures 195 and 196.
For grouping of non-scalar categories, select in the result of the Pivot Table all the individual
field values that you want to put in the one group.

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.

Chapter 8 Using Pivot Tables 238

Data Processing using advanced tools


Figure 196: Pivot
Table with non-scalar
Figure 195: Database with non-scalar categories
categories (departments)

Choose the Data > Group and Outline > Group from the Menu bar or press F12. The output
should now look like that in Figure 197. Repeat this for all groups that you want to create from
the different categories (Select Assembly, Production and Warehouse and Group again. The
output should look like Figure 198.

Figure 197: Summary of single categories in one


group Figure 198: Grouping finished

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.

Figure 200: Reduced to the new


groups

Figure 199: Renamed groups and partial results

Chapter 8 Using Pivot Tables 239

Data Processing using advanced tools


A well-structured database makes manual sorting within the Pivot Table obsolete. In
the example shown, you could add another column with the name Department, that
Note has the correct entry for each person based on whether the employee’s department
belongs to the group Office or Technical. The mapping for this (1:n relationship) can
be done easily with the VLOOKUP function from Calc.

Sorting the result


The result of any Pivot Table is sorted (categories) in columns and rows in ascending order.
You can change the sorting in three ways:
Select sort order from drop-down menus on each column heading.
Sort manually by using drag and drop.
Sort automatically by choosing the options in the preferences dialog of the row or column
field.

Select sort order from drop-down menus on each column heading


The simplest way to sort entries is to click the arrow on the right side of the heading and check
the box(es) for the desired sort order. The custom sorting dialog is shown in Figure 202.
Additional options exist to show all, show only the current item, or hide only the current item.
Once sorting has been carried out using the drop-down list, the color of the arrow changes and
a small square of matching color is added to the bottom right of the arrow button.

Figure 201: Arrow color change and indicator square on button

Figure 202: Custom sorting

Chapter 8 Using Pivot Tables 240

Data Processing using advanced tools


Sort manually by using drag and drop
You can change the order within the categories by moving the cells with the category values in
the result table of the Pivot Table. The cell will be inserted above the cell on which you drop it.
Be aware that in Calc, a cell must be selected. It is not enough that the cursor is in the cell. The
background of a selected cell is marked with a different color. To select several cells, click in one
cell with no extra key pressed, then press the Shift or Ctrl key while clicking in other cells. Another
possibility is to keep the mouse button pressed on the cell you want to select, move the mouse to
a neighbor cell, and then move back to the original cell before you release the mouse button.

Sort automatically
To sort automatically, right-click within the Pivot Table and choose Edit Layout. This will open the
Pivot Table (Figure 172). Within the Layout area of the Pivot Table, double-click the row or column
field you want to sort. In the Data Field dialog which opens (Figure 186), click Options to display
the Data Field Options dialog.
For Sort by, choose either Ascending or Descending. On the left side is a drop-down list where
you can choose the field this setting should apply to. With this method, you can specify that sorting
does not happen according to the categories but according to the results of the data field.

Figure 203: Options for a row or column field

Chapter 8 Using Pivot Tables 241

Data Processing using advanced tools


Drilling (showing details)
Drill allows you to show the related detailed data for a single, compressed value in the Pivot
Table result. To activate a drill, double-click on the cell or choose Data > Group and Outline >
Show Details. There are two possibilities:
The active cell is a row or column field.
In this case, drill means an additional breakdown into the categories of another field.
For example, double-click on the cell with the value golfing. In this instance the values
that are aggregated within golfing can be subdivided using another field.

Figure 204: Before the drill down for the category golfing

A dialog appears allowing you to select the field to use for further subdivision. In
this example, employee.

Figure 205: Selecting the field for the subdivision

Figure 206: After the drill down


To hide the details again, double-click on the cell golfing or choose Data > Group
and Outline > Hide Details.

Chapter 8 Using Pivot Tables 242

Data Processing using advanced tools


The Pivot Table remembers your selection (in our example the field employee) by
adding and hiding the selected field, so that for the next drill down for a category in the
field category the dialog does not appear. To remove the selection employee, open the
Pivot Table dialog by right-clicking and choosing Edit Layout, then delete the unwanted
selection in the row or column field.
The active cell is a value of the Data Field.
In this case, drill down results in a listing of all data entries of the data source that
aggregates to this value.
In our example, if we were to double-click on the cell with the value $18,741 from Figure
204, we would now have a new list of all data sets that are included in this value. This list
is displayed in a new sheet.

Figure 207: New table sheet after the drill down for a value in a data field

Filtering
To limit the Pivot Table analysis to a subset of the information that is contained in the data
basis, you can filter with the Pivot Table.

An Autofilter or default filter used on the sheet has no effect on the Pivot Table
Note analysis process. The Pivot Table always uses the complete list that was
selected when it was started.

To do this, click Filter on the top left side above the results.

Figure 208: Filter field in the upper left area of the Pivot Table
In the Filter dialog, you can define up to 3 filter options that are used in the same way as
Calc’s default filter.

Even if they are not called a filter, page fields are a practical way to filter the results.
Note The advantage is that the filtering criteria used are clearly visible.

Chapter 8 Using Pivot Tables 243

Data Processing using advanced tools


Figure 209: Dialog for defining the filter

Updating (refreshing) changed values


After you have created the Pivot Table, changes in the source data do not cause an automatic
update in the resulting table. You must update (refresh) the Pivot Table manually after
changing any of the underlying data values.
Changes in the source data could appear in two ways:
The content of existing data sets has been changed.
For example, you might have changed a sales value afterward. To update the Pivot Table,
right-click in the result area and choose Refresh (or choose Data > Pivot Table >
Refresh from the menu bar).
You have added or deleted data sets in the original list.
In this case the change means that the Pivot Table has to use a different area of the
spreadsheet for its analysis. Fundamental changes to the data set collection means
you must redo the Pivot Table from the beginning.

Cell formatting
The cells in the results area of the Pivot Table are automatically formatted in a simple format
by Calc. You can change this formatting using all the tools in Calc, but note that if you make
any change in the design of the Pivot Table or any updates, the formatting will return to the
format applied automatically by Calc.
For the number format in the data field, Calc uses the number format that is used in the
corresponding cell in the source list. In most cases, this is useful (for example, if the values are in
the currency format, then the corresponding cell in the result area is also formatted as currency).
However, if the result is a fraction or a percentage, the Pivot Table does not recognize that this
might be a problem; such results must either be without a unit or be displayed as a percentage.
Although you can correct the number format manually, the correction stays in effect only until the
next update.

Using shortcuts
If you use the Pivot Table very often, you might find the frequent use of the menu paths (Data
> Pivot Table > Create and Data > Group and Outline > Group) inconvenient.
For grouping, a shortcut is already defined: F12. For starting the Pivot Table, you can define your
own keyboard shortcut. If you prefer to have toolbar icons instead of keyboard shortcuts, you can
create a user-defined symbol and add it to either your own custom made toolbar or the Standard
toolbar.
For an explanation how to create keyboard shortcuts or add icons to toolbars, see Chapter 14,
Setting Up and Customizing Calc.

Chapter 8 Using Pivot Tables 244

Data Processing using advanced tools


Using Pivot Table results elsewhere

The problem
Normally, you create a reference to a value by entering the address of the cell that contains the
value. For example, the formula =C6*2 creates a reference to cell C6 and returns the doubled
value.
If this cell is located in the results area of the Pivot Table, it contains the result that was calculated
by referencing specific categories of the row and column fields. In Figure 210, the cell C6
contains the sum of the sales values of the employee Hans in the category Sailing. The formula in
the cell C12 uses this value.

Figure 210: Formula reference to a cell of the Pivot Table


If the underlying data or the layout of the Pivot Table changes, then you must take into account
that the sales value for Hans might appear in a different cell. Your formula still references the cell
C6 and therefore uses a wrong value. The correct value is in a different location. For example, in
Figure 211, the location is now C7.

Figure 211: The value that you really want to use can be found now in
a different location.

Chapter 8 Using Pivot Tables 245

Data Processing using advanced tools


Data Processing using advanced tools
Data Processing using advanced tools
Introduction
Once you are familiar with functions and formulas, the next step is to learn how to use
Calc’s automated processes to perform useful analysis of your data quickly.
Calc includes several tools to help you manipulate the information in your spreadsheets, ranging
from features for copying and reusing data, to creating subtotals automatically, to varying
information to help you find the answers you need. These tools are divided between the Tools
and Data menus.
If you are a newcomer to spreadsheets, these tools can be overwhelming at first. However, they
become simpler if you remember that they all depend on input from either a cell or a range of
cells that contain the data with which you are working.
You can always enter the cells or range manually, but in many cases it is easier to select the cells
with the mouse. Click the Shrink/Maximize icon beside a field to temporarily reduce the size of the
tool’s window, so you can see the spreadsheet underneath and select the cells required.
Sometimes, you may have to experiment to find out which data goes into which field, but then
you can set a selection of options, many of which can be ignored in any given case. Just keep the
basic purpose of each tool in mind, and you should have little trouble with Calc’s function tools.
You don’t need to learn them, especially if your spreadsheet use is simple, but as your
manipulation of data becomes more sophisticated, they can save time in making calculations,
especially as you start to deal with hypothetical situations. Just as importantly, they can allow
you to preserve your work and to share it with other people—or yourself at a later session.
One function tool not mentioned here is Pivot Table, but it is a topic that is sufficiently complex
that it requires a separate chapter: see Chapter 8 in this book.

Consolidating data
Data > Consolidate provides a way to combine data from two or more ranges of cells into a new
range while running one of several functions (such as Sum or Average) on the data. During
consolidation, the contents of cells from several sheets can be combined into one place. The
effect is that copies of the identified ranges are stacked with their top left corners at the specified
result position, and the selected operation is used in each cell to calculate the result value.
Open the document containing the cell ranges to be consolidated.
Choose Data > Consolidate to open the Consolidate dialog. Figure 215 shows this
dialog after making the changes described below.
The Source data range list contains any existing named ranges (created using Data
> Define Range) so you can quickly select one to consolidate with other areas.
If the source range is not named, click in the field to the right of the drop-down list and
either type a reference for the first source data range or use the mouse to select the
range on the sheet. (You may need to move the Consolidate dialog or click on the Shrink
icon to reach the required cells.)
Click Add. The selected range is added to the Consolidation ranges list.
Select additional ranges and click Add after each selection.
Specify where you want to display the result by selecting a target range from the
Copy results to drop-down list.
If the target range is not named, click in the field next to Copy results to and enter the
reference of the target range or select the range using the mouse or position the cursor
in the top left cell of the target range. Copy results to takes only the first cell of the target
range instead of the entire range as is the case for Source data range.

Chapter 9 Data Analysis 250

Data Processing using advanced tools


Figure 215: Defining the data to be consolidated

Select a function from the Function list. This specifies how the values of the consolidation
ranges will be calculated. The default setting is Sum, which adds the corresponding cell
values of the Source data range and gives the result in the target range.
Most of the available functions are statistical (such as Average, Min, Max, Stdev), and
the tool is most useful when you are working with the same data over and over.
At this point you can click More in the Consolidate dialog to access the following
additional settings:
In the Options section, select Link to source data to insert the formulas that generate
the results into the target range, rather than the actual results. If you link the data, any
values modified in the source range are automatically updated in the target range.

Caution The corresponding cell references in the target range are inserted in
consecutive rows, which are automatically ordered and then hidden from view.
Only the final result, based on the selected function, is displayed.

In the Consolidate by section, select either Row labels or Column labels if the cells
of the source data range are not to be consolidated corresponding to the identical
position of the cell in the range, but instead according to a matching row label or
column label. To consolidate by row labels or column labels, the label must be
contained in the selected source ranges. The text in the labels must be identical, so
that rows or columns can be accurately matched. If the row or column label of one
source data range does not match any that exist in other source data ranges, it is
added to the target range as a new row or column.
Click OK to consolidate the ranges.

If you are continually working with the same range, then you probably want to use
Tip Data > Define Range to give it a name.

The consolidation ranges and target range are saved as part of the document. If you later open a
document in which consolidation has been defined, this data is still available.

Chapter 9 Data Analysis 251

Data Processing using advanced tools


Creating subtotals
Subtotals are implemented in two ways:
The SUBTOTAL function
Data > Subtotals from the menu bar.

Using the SUBTOTAL function


SUBTOTAL is listed under the Mathematical category when you use the Function Wizard (Insert >
Function or press Ctrl+F2). This function is a relatively limited method for generating a subtotal.
To obtain a subtotal for our sales information for the employee Brigitte, we must first implement an
AutoFilter on the data (Data > Filter > AutoFilter). This displays the selection arrows to the right
of each column header; select Brigitte in the Employee field as shown in Figure 216.

Figure 216: AutoFilter applied and Brigitte selected in the Employee column
Select the location for the subtotal to be displayed by clicking in the chosen cell.
Select Insert > Function from the Menu bar, or click the Function Wizard button on
the Function Bar, or press Ctrl+F2 to open the Function Wizard.
Select SUBTOTAL from the function list in the Function Wizard dialog and click Next>>
at the bottom of the dialog.
Enter the required information into the two input boxes as shown in Figure 217. The range
is selected from the filtered data, and the function is selected from the list of available
possible functions as shown in the Help file extract of Figure 218. In our example we
select the sales figures (column B) and we require the sum total (function index 9).
Click OK to return the summed values of Brigitte’s sales (Figure 219).

Chapter 9 Data Analysis 252

Data Processing using advanced tools


Figure 217: Enter the information into the two input boxes

Figure 218: Function indexes for available functions

Figure 219: SUBTOTAL result for Brigitte's sales

Chapter 9 Data Analysis 253

Data Processing using advanced tools


You will appreciate that this is a tedious and time consuming exercise for a sales report if you
want to subtotal for more than a couple of categories.

Using Data > Subtotals


A more comprehensive solution is to create subtotals using Data > Subtotals from the Menu bar,
which opens the Subtotals dialog. Subtotal creates totals for data arranged in an array—that is, a
group of cells with labels for columns. Using the Subtotals dialog, you can select up to three
arrays, then choose a statistical function to apply to them. When you click OK , Calc adds subtotal
and grand total rows to the selected arrays, using the Result and Result2 cell styles to
differentiate those entries. By default, matching items throughout your array will be gathered
together as a single group above a subtotal.
To insert subtotal values into a sheet:
Ensure that the columns have labels (we will use our sales data example again).
Select, or click in a single cell in the range of cells that you want to calculate subtotals
for, and then choose Data > Subtotals.
In the Subtotals dialog (Figure 220), in the Group by list, select the column by which
the subtotals need to be grouped. A subtotal will be calculated for each distinct value in
this column.
In the Calculate subtotals for box, select the columns containing the values that you
want to create subtotals for. If the contents of the selected columns change later, the
subtotals are automatically recalculated.
In the Use function box, select the function that you want to use to calculate the subtotals.
You can create a further two Group by subtotals using the 2nd Group and 3rd Group
tabs and repeating steps 3 to 5.
Click OK.

Figure 220: Setting up subtotals

A partial view of the results using our example data is shown in Figure 221. Subtotals for Sales
by Employee and Category were used
Calc inserts, to the left of the row numbering labels, an outline area that graphically represents
the structure of the subtotals. Number 1 represents the highest level of grouping, the Grand Total.
Numbers 2 to 4 show reducing grouping levels, with number 4 showing individual entries. The
number of levels depends on the number of groupings in the subtotals.

Chapter 9 Data Analysis 254

Data Processing using advanced tools


Figure 221: Subtotals are calculated for each employee (partial
view) using the 1st Group and 2nd Group
Clicking on a number at the top of the column shrinks the structure of that element of the subtotal.
For column 1, this changes the minus button in the column to one with a plus symbol, indicating
that it is expandable. For column 2 and others with content, each element of the column shrinks,
and each button changes to a plus. For our example subtotal displayed in Figure 221, the
structure which is displayed is Column 1 is the Grand Total, column 2 is the Employee subtotal,
and column 3 is the Category subtotal.
For column 2, and for others if you have more groups, you can also click each individual minus
button to shrink only that subtotal. If you click on the numbered button at the top, you must then
click on the resultant plus buttons to expand the structure again (see Figure 222). Shrinking any
element, temporarily hides any element contained in a column to its right. In Figure 222
Individual entries are hidden by shrinking the Category subtotals for Brigitte.
To turn off outlines, select Data > Group and Outline > Remove from the Menu bar.
Select AutoOutline to reinstate the outlines.

Figure 222: Click the plus buttons to expand the elements again

Chapter 9 Data Analysis 255

Data Processing using advanced tools


Further choices are available in the Options page of the Subtotals dialog.
In the Groups section:
Selecting Page break between groups inserts a new page after each group of subtotaled
data.
Selecting Case sensitive recalculates subtotals when you change the case of a data label.
Selecting the Pre-sort area according to groups option sorts the area that you selected in
the Group by box of the Group tabs according to the columns that you selected.
In the Sort section:
Selecting Ascending or Descending, sorts beginning with the lowest or the highest value.
You can define the sort rules on Data > Sort > Options.
Selecting Include formats option gives consideration to the formatting attributes when
sorting.
Selecting Custom sort order sorts according to one of the predefined custom sorts defined in
Tools > Options > LibreOffice Calc > Sort Lists.

Figure 223: Choosing options for subtotals

Using “what if” scenarios


The Scenario is a tool to test “what-if” questions. Each scenario is named, and can be edited and
formatted separately. When you print the spreadsheet, only the contents of the currently active
scenario are printed.
A scenario is essentially a saved set of cell values for your calculations. You can easily switch
between these sets using the Navigator or a drop-down list which can be shown beside the
changing cells. For example, if you wanted to calculate the effect of different interest rates on an
investment, you could add a scenario for each interest rate, and quickly view the results.
Formulas that rely on the values changed by your scenario are updated when the scenario is
opened. If all your sources of income used scenarios, you could efficiently build a complex model
of your possible income.

Chapter 9 Data Analysis 256

Data Processing using advanced tools


Creating scenarios
Tools > Scenarios opens a dialog with options for creating a scenario.
To create a new scenario:
Select the cells that contain the values that will change between scenarios. To select
multiple ranges, hold down the Ctrl key as you click. You must select at least two cells.
Choose Tools > Scenarios.
On the Create Scenario dialog (Figure 224), enter a name for the new scenario. It’s best
to use a name that clearly identifies the scenario, not the default name as shown in the
illustration. This name is displayed in the Navigator and in the title bar of the border
around the scenario on the sheet itself.

Figure 224: Creating a scenario

Optionally add some information to the Comment box. The example shows the default
comment. This information is displayed in the Navigator when you click the Scenarios
icon and select the desired scenario.
Optionally select or deselect the options in the Settings section. See below for more
information about these options.
Click OK to close the dialog. The new scenario is automatically activated.
You can create several scenarios for any given range of cells.

Settings
The lower portion of the Create Scenario dialog contains several options. The default settings
(as shown in Figure 224) are likely to be suitable in most situations.

Display border
Places a border around the range of cells that your scenario alters. To choose the color of the
border, use the field to the right of this option. The border has a title bar displaying the name
of the active scenario. Click the arrow button to the right of the scenario name to open a drop-
down list of all the scenarios that have been defined for the cells within the border. You can
choose any of the scenarios from this list at any time.

Chapter 9 Data Analysis 257

Data Processing using advanced tools


Copy back
Copies any changes you make to the values of scenario cells back into the active scenario. If
you do not select this option, the saved scenario values are never changed when you make
changes. The actual behavior of the Copy back setting depends on the cell protection, the
sheet protection, and the Prevent changes setting (see Table 8 on page 258).
If you are viewing a scenario which has Copy back enabled and then create a new
Caution scenario by changing the values and selecting Tools > Scenarios, you also
inadvertently overwrite the values in the first scenario.
This is easily avoided if you leave the current values alone, create a new scenario
with Copy back enabled, and then change the values only when you are viewing
the new scenario.

Copy entire sheet


Adds to your document a sheet that permanently displays the new scenario in full. This is in
addition to creating the scenario and making it selectable on the original sheet as normal.

Prevent changes
Prevents changes to a scenario enabled as a Copy back, when the sheet is protected but the cells
are not. Also prevents changes to the settings described in this section while the sheet is protected.
A fuller explanation of the effect this option has in different situations is given below.

Changing scenarios
Scenarios have two aspects that can be altered independently:
Scenario properties (the settings described above)
Scenario cell values (the entries within the scenario border)
The extent to which either of these aspects can be changed is dependent upon both the
existing properties of the scenario and the current protection state of the sheet and cells.

Changing scenario properties


If the sheet is protected ( Tools > Protect Document > Sheet), and Prevent changes is
selected then scenario properties cannot be changed.
If the sheet is protected, and Prevent changes is not selected, then all scenario properties can
be changed except Prevent changes and Copy entire sheet, which are disabled.
If the sheet is not protected, then Prevent changes does not have any effect, and all
scenario properties can be changed.

Changing scenario cell values


Table 8 summarizes the interaction of various settings in preventing or allowing changes
in scenario cell values.

Table 8: Prevent changes behavior for scenario cell value changes

Settings Change allowed


Sheet protection ON Scenario cell values cannot be changed.
Scenario cell protection OFF
Prevent changes ON
Copy back ON

Chapter 9 Data Analysis 258

Data Processing using advanced tools


Settings Change allowed
Sheet protection ON Scenario cell values can be changed, and the
Scenario cell protection OFF scenario is updated.
Prevent changes OFF
Copy back ON
Sheet protection ON Scenario cell values can be changed, but the
scenario is not updated due to the Copy back
Scenario cell protection OFF
setting.
Prevent changes ON or OFF
Copy back OFF
Sheet protection ON Scenario cell values cannot be changed.
Scenario cell protection ON
Prevent changes ANY SETTING
Copy back ANY SETTING
Sheet protection OFF Scenario cell values can be changed and the
Scenario cell protection ANY scenario is updated or not, depending on the
Copy back setting.
SETTING Prevent changes ANY
SETTING Copy back ANY SETTING

Working with scenarios using the Navigator


After scenarios are added to a spreadsheet, you can jump to a particular scenario by selecting
it from the list in the Navigator.
Click the Scenarios icon in the Navigator (see Figure 225). The defined scenarios are listed, along
with the comments that were entered when the scenarios were created.

Figure 225: Scenarios in the Navigator


To apply a scenario to the current sheet, double-click the scenario name in the Navigator.
To delete a scenario, right-click the name in the Navigator and choose Delete.
To edit a scenario, including its name and comments, right- click the name in the Navigator
and choose Properties. The Edit Properties dialog is the same as the Create Scenario dialog
(Figure 224).

Chapter 9 Data Analysis 259

Data Processing using advanced tools


Tracking values in scenarios
To learn which values in the scenario affect other values, choose Tools > Detective > Trace
Dependents. Arrows point to the cells that are directly dependent on the current cell.

Using other “what if” tools


Like scenarios, Data > Multiple Operations is a planning tool for “what if” questions. Unlike a
scenario, the Multiple Operations tool does not present the alternate versions in the same cells or
with a drop-down list. Instead, the Multiple Operations tool creates a formula array: a separate
set of cells showing the results of applying the formula to a list of alternative values for the
variables used by the formula. Although this tool is not listed among the functions, it is really a
function that acts on other functions, allowing you to calculate different results without having to
enter and run them separately.
To use the Multiple Operations tool, you need two arrays of cells. The first array contains the
original or default values and the formulas applied to them. The formulas must be in a range.
The second array is the formula array. It is created by entering a list of alternative values for one
or two of the original values.
Once the alternative values are created, you use the Multiple Operations tool to specify which
formulas you are using, as well as the original values used by the formulas. The second array
is then filled with the results of using each alternative value in place of the original values.
The Multiple Operations tool can use any number of formulas, but only one or two variables. With
one variable, the formula array of alternative values for the variables will be in a single column or
row. With two variables, you should outline a table of cells such that the alternative values for one
variable are arranged as column headings, and the alternative values for the other variable act as
row headings.
Setting up multiple operations can be confusing at first. For example, when using two variables, you
need to select them carefully, so that they form a meaningful table. Not every pair of variables is
useful to add to the same formula array. Yet, even when working with a single variable, a new user
can easily make mistakes or forget the relationships between cells in the original array and cells in the
formula array. In these situations, Tools > Detective can help to clarify the relations.
You can also make formula arrays easier to work with if you apply some simple design logic.
Place the original and the formula array close together on the same sheet, and use labels for the
rows and columns in both. These small exercises in organizational design make working with the
formula array much less painful, particularly when you are correcting mistakes or adjusting results.

If you export a spreadsheet containing multiple operations to Microsoft Excel, the


Note location of the cells containing the formula must be fully defined relative to the
data range.

Multiple operations in columns or rows


In your spreadsheet, enter a formula to calculate a result from values that are stored in other
cells. Then, set up a cell range containing a list of alternatives for one of the values used in the
formula. The Multiple Operations command produces a list of results adjacent to your alternative
values by running the formula against each of these alternatives.

Chapter 9 Data Analysis 260

Data Processing using advanced tools


Before you choose the Data > Multiple Operations option, be sure to select not only
Note your list of alternative values but also the adjacent cells into which the results
should be placed.

In the Formulas field of the Multiple Operations dialog, enter the cell reference to the formula that
you wish to use.
The arrangement of your alternative values dictates how you should complete the rest of the
dialog. If you have listed them in a single column, you should complete the field for Column input
cell. If they are along a single row, complete the Row input cell field. You may also use both in
more advanced cases. Both single and double-variable versions are explained below.
The above can be explained best by examples. Cell references correspond to those in
the following figures.
Let’s say you produce toys that you sell for $10 each (cell B1). Each toy costs $2 to make (cell
B2), in addition to which you have fixed costs of $10,000 per year (cell B3). How much profit will
you make in a year if you sell a particular number of toys?

Calculating with one formula and one variable


To calculate the profit, first enter any number as the quantity (items sold); in this example,
2000 (cell B4). The profit is found from the formula Profit=Quantity * (Selling price – Direct
costs) – Fixed costs. Enter this formula in B5: =B4*(B1-B2)-B3.
In column D enter a variety of alternative annual sales figures, one below the other;
for example, 500 to 5000, in steps of 500.
Select the range D2:E11, and thus the values in column D and the empty cells (which
will receive the results of the calculations) alongside in column E.
Choose Data > Multiple Operations.
With the cursor in the Formulas field of the Multiple operations dialog, click cell B5.
Set the cursor in the Column input cell field and click cell B4. This means that B4, the
quantity, is the variable in the formula, which is to be replaced by the column of
alternative values. Figure 226 shows the worksheet and the Multiple operations dialog.
Click OK. The profits for the different quantities are now shown in column E. See
Figure 227.

You may find it easier to mark the required reference in the sheet if you click the

Tip Shrink icon to reduce the Multiple operations dialog to the size of the input field. The
icon then changes to the Maximize icon; click it to restore the dialog to its original size.

Chapter 9 Data Analysis 261

Data Processing using advanced tools


Figure 226: Sheet and Multiple operations dialog showing input

Figure 227: Sheet showing results of multiple operations calculations

Calculating with several formulas simultaneously


In the sheet from the previous example, delete the contents of column E.
Enter the following formula in C5: =B5/B4. You are now calculating the annual profit per
item sold.
Select the range D2:F11, thus three columns.
Choose Data > Multiple Operations.

Chapter 9 Data Analysis 262

Data Processing using advanced tools


With the cursor in the Formulas field of the Multiple operations dialog, select cells B5
and C5.
Set the cursor in the Column input cell field and click cell B4. Figure 228 shows the
worksheet and the Multiple operations dialog.

Figure 228: Sheet and dialog showing input


7) Click OK. Now the profits are listed in column E and the annual profit per item in column F.

Figure 229: Results of multiple operations calculations

Multiple operations across rows and columns


You can carry out multiple operations simultaneously for both columns and rows in so-called cross-
tables. The formula must use at least two variables, the alternative values for which should be arranged
so that one set is along a single row and the other set appears in a single column. These

Chapter 9 Data Analysis 263

Data Processing using advanced tools


two sets of alternative values will form column and row headings for the results table produced
by the Multiple Operations procedure.
Select the range defined by both data ranges (thus including all of the blank cells that are to
contain the results) and choose Data > Multiple operations. Enter the cell reference to the
formula in the Formulas field. The Row input cell and the Column input cell fields are used to
enter the reference to the corresponding cells of the formula.

Beware of entering the cell reference of a variable into the wrong field. The Row input
Caution cell field should contain not the cell reference of the variable which changes down the
rows of your results table, but that of the variable whose alternative values have been
entered along a single row.

Calculating with two variables


You now want to vary not just the quantity produced annually, but also the selling price, and
you are interested in the profit in each case.
Expand the table shown in Figure 228. D2 thru D11 already contain the numbers 500, 1000 and
so on, up to 5000. In E1 through H1 enter the numbers 8, 10, 15 and 20.
Select the range D1:H11.
Choose Data > Multiple Operations.

Figure 230: Sheet and dialog showing input

With the cursor in the Formulas field of the Multiple operations dialog, click cell B5 (profit).
Set the cursor in the Row input cell field and click cell B1. This means that B1, the
selling price, is the horizontally entered variable (with the values 8, 10, 15 and 20).
Set the cursor in the Column input cell field and click cell B4. This means that B4,
the quantity, is the vertically entered variable.
Click OK. The profits for the different selling prices are now shown in the range
E2:H11 (See Figure 231).

Chapter 9 Data Analysis 264

Data Processing using advanced tools


Figure 231: Results of multiple operations calculations

Working backwards using Goal Seek


Usually, you create a formula to calculate a result based upon existing values. By contrast,
using Tools > Goal Seek you can discover what values will produce the result that you want.
To take a simple example, imagine that the Chief Financial Officer of a company is developing
sales projections for each quarter of the forthcoming year. She knows what the company’s total
income must be for the year to satisfy stockholders. She also has a good idea of the company’s
income in the first three quarters, because of the contracts that are already signed. For the
fourth quarter, however, no definite income is available. So how much must the company earn in
Q4 to reach its goal? The CFO can enter the projected earnings for each of the other three
quarters along with a formula that totals all four quarters. Then she runs a goal seek on the
empty cell for Q4 sales, and receives her answer.
Other uses of goal seek may be more complicated, but the method remains the same. Only
one argument can be altered in a single goal seek.

Goal Seek example


To calculate annual interest (I), create a table with the values for the capital (C), number of
years (n), and interest rate (i). The formula is I = C*n*i.
Let us assume that the interest rate i of 7.5% and the number of years n (1) will remain constant.
However, you want to know how much the investment capital C would have to be modified in
order to attain a particular return I. For this example, calculate how much capital C would be
required if you want an annual return of $15,000.
Enter each of the values mentioned above into adjacent cells (for Capital, C, an arbitrary value
like $100,000 or it can be left blank; for number of years, n, 1; for interest rate, i, 7.5%). Enter the
formula to calculate the interest, I, in another cell. Instead of C, n, and i, use the reference to the
cell with the corresponding value. In our example (Figure 232), this would be =B1*B2*B3.
Place the cursor in the formula cell (B4), and choose Tools > Goal Seek.
In the Goal Seek dialog, the correct cell is already entered in the Formula cell field.
Place the cursor in the Variable cell field. In the sheet, click in the cell that contains
the value to be changed, in this example it is B1.
Enter the desired result of the formula in the Target value field. In this example, the value
is 15000. Figure 232 shows the cells and fields.

Chapter 9 Data Analysis 265

Data Processing using advanced tools


Figure 232: Example setup for goal seek
Click OK. A dialog appears informing you that the Goal Seek was successful. Click Yes
to enter the goal value into the variable cell. The result is shown below indicating a
capital requirement of $200,000 is needed to achieve $15,000 annual return.

Figure 233: Result of goal seek operation

Using the Solver


Tools > Solver amounts to a more elaborate form of Goal Seek. The difference is that the
Solver deals with equations with multiple unknown variables. It is specifically designed to
minimize or maximize the result according to a set of rules that you define.
Each of these rules defines whether an argument in the formula should be greater than, less than,
or equal to the figure you enter. If you want the argument to remain unchanged, you must enter a
rule that specifically states that the cell should be equal to its current entry. For arguments that
you would like to change, you need to add two rules to define a range of possible values: the
limiting conditions. For example, you can set the constraint that one of the variables or cells must
not be bigger than another variable, or not bigger than a given value. You can also define the
constraint that one or more variables must be integers (values without decimals), or binary values
(where only 0 and 1 are allowed).
Once you have finished setting up the rules, click the Solve button to begin the automatic process
of adjusting values and calculating results. Depending on the complexity of the task, this may take
some time.

Chapter 9 Data Analysis 266

Data Processing using advanced tools


Solver example
Let’s say you have $10,000 that you want to invest in two mutual funds for one year. Fund X is
a low risk fund with 8% interest rate and Fund Y is a higher risk fund with 12% interest rate.
How much money should be invested in each fund to earn a total interest of $1000?
To find the answer using Solver:
Enter labels and data:
Row labels: Fund X, Fund Y, and total, in cells A2 thru A4.
Column labels: interest earned, amount invested, interest rate, and time
period, in cells B1 thru E1.
Interest rates: 8 and 12, in cells D2 and D3.
Time period: 1, in cells E2 and E3.
Total amount invested: 10000, in cell C4.
Enter an arbitrary value (0 or leave blank) in cell C2 as amount invested in Fund X.
Enter formulas:
In cell C3, enter the formula C4–C2 (total amount – amount invested in Fund X) as
the amount invested in Fund Y.
In cells B2 and B3, enter the formula for calculating the interest earned (see
Figure 234).
In cell B4, enter the formula B2+B3 as the total interest earned.

Figure 234: Example setup for Solver

Choose Tools > Solver. The Solver dialog (Figure 235) opens.
Click in the Target cell field. In the sheet, click in the cell that contains the target value.
In this example it is cell B4 containing total interest value.
Select Value of and enter 1000 in the field next to it. In this example, the target cell value is
1000 because your target is a total interest earned of $1000. Select Maximum or Minimum
if the target cell value needs to be one of those extremes.
Click in the By changing cells field and click on cell C2 in the sheet. In this example,
you need to find the amount invested in Fund X (cell C2).
Enter limiting conditions for the variables by selecting the Cell reference, Operator and
Value fields. In this example, the amount invested in Fund X (cell C2) should not be
greater than the total amount available (cell C4) and should not be less than 0.
Click OK. A dialog appears informing you that the Solving successfully finished. Click
Keep Result to enter the result in the cell with the variable value. The result is shown in
Figure 236.

Chapter 9 Data Analysis 267

Data Processing using advanced tools


Figure 235: The Solver dialog

Figure 236: Result of Solver operation

Chapter 9 Data Analysis 268

Data Processing using advanced tools


Data Processing using advanced tools
Introduction
A macro is a saved sequence of commands or keystrokes that are stored for later use. An
example of a simple macro is one that “types” your address. The LibreOffice macro language is
very flexible, allowing automation of both simple and complex tasks. Macros are especially useful
to repeat a task the same way over and over again. This chapter briefly discusses common
problems related to macro programming using Calc.

Using the macro recorder


Chapter 13 of the Getting Started guide, Getting Started with Macros, provides a basis for
understanding the general macro capabilities in LibreOffice using the macro recorder. An
example is shown here without the explanations in the Getting Started guide. The following steps
create a macro that performs paste special with multiply.

Use Tools > Options > LibreOffice > Advanced and select the Enable macro
Tip recording option to enable the macro recorder.

Open a new spreadsheet.


Enter numbers into a sheet.

Figure 285: Enter numbers


Select cell A3, which contains the number 3, and copy the value to the clipboard.
Select the range A1:C3.
Use Tools > Macros > Record Macro to start the macro recorder. The Record
Macro dialog is displayed with a stop recording button.

Figure 286: Stop recording button


6) Use Edit > Paste Special to open the Paste Special dialog (Figure 287).

Figure 287: Paste Special dialog

Chapter 12 Calc Macros 308

Data Processing using advanced tools


7) Set the operation to Multiply and click OK. The cells are now multiplied by 3 (Figure 288).

Figure 288: Cells multiplied by 3


Click Stop Recording to stop the macro recorder. The LibreOffice Basic Macros
dialog (Figure 289) opens.

1 My Macros 5 Create new module in library


2 LibreOffice Macros 6 Macros in selected library
3 Open documents 7 Current document
4 Create new library 8 Expand/collapse list
Figure 289: Parts of the LibreOffice Basic Macros dialog
Select the current document. For this example, it is Untitled 1. Existing documents show a
library named Standard. This library is not created until the document is saved or the
library is needed, so at this point your new document does not contain a library. You can
create a new library to contain the macro, but this is not necessary.
Click New Module. If no libraries exist, then the Standard library is automatically created and
used. In the New Module dialog, type a name for the new module or leave the name as
Module1.

Chapter 12 Calc Macros 309

Data Processing using advanced tools


The libraries, modules and macro names must follow some strict rules.
Following the main rules, the names must:
• Begin with a letter
Note
• Not contain spaces
• Not contain special caracters, accents included, except for _ (underscore)

11) Click OK to create a new module named Module1. Select the newly created Module1, type
PasteMultiply in the Macro name box at the upper left, and click Save. (See Figure 290.)

Figure 290: Select the module and name the macro

The created macro is saved in Module1 of the Standard library in the Untitled 1 document. Listing 1
shows the contents of the macro.
Listing 1. Paste special with multiply.
sub PasteMultiply
rem --------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem --------------------------------------------------------------

rem get access to the document


document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem --------------------------------------------------------------
dim args1(5) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Flags"
args1(0).Value = "A"
args1(1).Name = "FormulaCommand"
args1(1).Value = 3
args1(2).Name = "SkipEmptyCells"

Chapter 12 Calc Macros 310

Data Processing using advanced tools


args1(2).Value = false
args1(3).Name = "Transpose"
args1(3).Value = false
args1(4).Name = "AsLink"
args1(4).Value = false
args1(5).Name = "MoveMode"
args1(5).Value = 4

dispatcher.executeDispatch(document, ".uno:InsertContents", "", 0, args1()) end sub

More detail on recording macros is provided in Chapter 13, Getting Started with Macros, in the
Getting Started guide; we recommend you read it if you have not already done so. More detail
is also provided in the following sections, but not as related to recording macros.

Write your own functions


Calc can call macros as Calc functions. Use the following steps to create a simple macro:
Create a new Calc document named CalcTestMacros.ods.
Use Tools > Macros > Organize Macros > LibreOffice Basic to open the LibreOffice
Basic Macros dialog. The Macro from box lists available macro library containers including
currently open LibreOffice documents. My Macros contains macros that you write or add
to LibreOffice. LibreOffice Macros contains macros included with LibreOffice and should
not be changed.

Figure 291: LibreOffice Basic Macros dialog

Chapter 12 Calc Macros 311

Data Processing using advanced tools


Source: - Libre Office Calc Guide: Version 4.1
https://documentation.libreoffice.org/assets/Uploads/Documentation/en/CG4.1/CG41CalcGuideLO.pdf

Data Processing using advanced tools

You might also like