38
Working with Data LibreOffice Calc

Libre Office Calc Lesson 5: Working with Data

Embed Size (px)

DESCRIPTION

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. Data Analysis Creating subtotals Sharing documents Saving versions Calc Macros

Citation preview

Page 1: Libre Office Calc Lesson 5: Working with Data

Working with DataLibreOffice Calc

Page 2: Libre Office Calc Lesson 5: Working with Data

Lesson 5 Outline• Data Analysis• Creating subtotals• Sharing documents• Saving versions• Calc Macros

Page 3: Libre Office Calc Lesson 5: Working with Data

Consolidating DataData > 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.

Page 4: Libre Office Calc Lesson 5: Working with Data

Using Consolidating Data1) Open the document containing the cell ranges to be consolidated.2) Choose Data > Consolidate to open the Consolidate dialog. Figure 1 shows this dialog after making the changes described below.3) 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 andeither type a reference for the first source data range or use the mouse to select the rangeon the sheet. (You may need to move the Consolidate dialog or click on the Shrink icon to reach the required cells.)

4) Click Add. The selected range is added to the Consolidation ranges list.5) Select additional ranges and click Add after each selection.6) 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 thereference of the target range or select the range using the mouse or position the cursor inthe top left cell of the target range. Copy results to takes only the first cell of the targetrange instead of the entire range as is the case for Source data range.

Page 5: Libre Office Calc Lesson 5: Working with Data

Defining the data to be consolidated

7) 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.8) 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 generatethe results into the target range, rather than the actual results. If you link the data, anyvalues modified in the source range are automatically updated In the target range.9) Click OK to consolidate the ranges.

Page 6: Libre Office Calc Lesson 5: Working with Data

Creating subtotalsSubtotals are implemented in two ways:

• The SUBTOTAL function• Data > Subtotals from the menu bar.

Page 7: Libre Office Calc Lesson 5: Working with Data

Using the SUBTOTAL functionSUBTOTAL 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, partially shown in Figure 2, for the employee Brigitte we must first implement an AutoFilter on the data, selecting Brigitte in the Employee field afterwards as shown in Figure 3.

Figure 2

Figure 3

Page 8: Libre Office Calc Lesson 5: Working with Data

Subtotal Function1) Select the location for the subtotal to be displayed by clicking in

the chosen cell.

2) Select Insert > Function from the Menu bar, or press Ctrl+F2.

3) Select SUBTOTAL from the function list in the Function Wizard dialog.

4) Enter the required information into the two input boxes as shown in Figure 2. 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 3. In our example we select the sales figures (B5:B23) and we require the sum total (function index 9).

5) Click OK to return the summed values of Brigitte’s sales (Figure 4).

Page 9: Libre Office Calc Lesson 5: Working with Data

Subtotal Dialog Box

Page 10: Libre Office Calc Lesson 5: Working with Data

Using Data > SubtotalsA 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 subtotaland 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:

1) Ensure that the columns have labels (we will use our sales data example again).2) Select, or click in a single cell in the range of cells that you want to calculate subtotals for,and then choose Data > Subtotals.3) In the Subtotals dialog (Figure 7), 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.4) 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.5) In the Use function box, select the function that you want to use to calculate the subtotals.6) You can create a further two Group by subtotals using the 2nd Group and 3rd Group tabs and repeating steps 3 to 5.7) Click OK.

Page 11: Libre Office Calc Lesson 5: Working with Data

Working with Subtotals

A partial view of the results using our example data is shown in Figure 8. Subtotals for Sales by Employee and Category were used.

Page 12: Libre Office Calc Lesson 5: Working with Data

Grouping SubtotalsCalc 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 is dependent on the number of groupings in the subtotals.

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 8, 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.

Page 13: Libre Office Calc Lesson 5: Working with Data

AutoOutliningFor 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. Shrinking any element, temporarily hides any element contained in a column to its right. In image to the right, 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.

Page 14: Libre Office Calc Lesson 5: Working with Data

Groups and SortsIn 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.

Page 15: Libre Office Calc Lesson 5: Working with Data

Sorting

Page 16: Libre Office Calc Lesson 5: Working with Data

Using “what if” scenariosThe Scenario is a tool to test “what-if” questions. Each scenario is named, and can be edited andformatted separately. When you print the spreadsheet, only the contents of the currently activescenario are printed.

A scenario is essentially a saved set of cell values for your calculations. You can easily switchbetween these sets using the Navigator or a drop-down list which can be shown beside thechanging cells. For example, if you wanted to calculate the effect of different interest rates on aninvestment, 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.

Page 17: Libre Office Calc Lesson 5: Working with Data

Creating scenariosTools > Scenarios opens a dialog with options for creating a scenario.To create a new scenario:1) 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.2) Choose Tools > Scenarios.3) On the Create Scenario dialog (image to the right), 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.4) 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.5) Optionally select or deselect the options in the Settings section. See below for more information about these options.6) Click OK to close the dialog. The new scenario is automatically activated.

Page 18: Libre Office Calc Lesson 5: Working with Data

Changing scenariosScenarios 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.

Page 19: Libre Office Calc Lesson 5: Working with Data

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.

Page 20: Libre Office Calc Lesson 5: Working with Data

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 (Image to the right). The defined scenarios are listed, along with the comments that were entered when the scenarios were created.

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

Page 21: Libre Office Calc Lesson 5: Working with Data

Sharing documentsIn LibreOffice Writer, Impress, and Draw, only one user at a time can open any document for editing. In Calc, many users can open the same spreadsheet for writing at the same time.

Each user who wants to collaborate should be sure to enter a name on the Tools > Options > LibreOffice > User Data page.

Some menu commands are not available (grayed out) when change tracking or document sharing is activated

Page 22: Libre Office Calc Lesson 5: Working with Data

Setting up a spreadsheet for sharing

At any time, you can set up a spreadsheet for sharing with others. With the spreadsheet documentopen, choose Tools > Share Document to activate the collaboration features for this document. Adialog opens where you can enable or disable sharing.

To enable sharing, check the box at the top of the dialog, and then click OK. A message appearsstating that you must save the document to activate shared mode. Click Yes to continue. The word(shared) is then shown on the title bar after the document’s title.

The Tools > Share Document command can be used to switch the mode for a document from unshared to shared. However, if you want to use a shared document in unshared mode, you need to save the shared document using another name or path. This creates a copy of the spreadsheet that is not shared.

Page 23: Libre Office Calc Lesson 5: Working with Data

Opening a shared spreadsheet

The following features are disabled in a shared spreadsheet document:Edit > Changes, except for Merge DocumentEdit > Compare DocumentEdit > Sheet > Move/Copy & DeleteInsert > Cells > Shift Cells Down & Shift Cells RightInsert > Sheet from fileInsert > NamesInsert > CommentInsert > Picture > From FileInsert > Movie and SoundInsert > ObjectInsert > ChartInsert > Floating Frame

Format > Sheet > Rename, Tab ColorFormat > Merge Cells > Merge and Center, Merge Cells, Split CellsFormat > Print RangesTools > Protect DocumentData > Define RangeData > SortData > SubtotalsData > ValidityData > Multiple OperationsData > ConsolidateData > Group and Outline (all)Data > Pivot Table

Page 24: Libre Office Calc Lesson 5: Working with Data

Saving a shared spreadsheetWhen you save a shared spreadsheet, one of several situations may occur:• If the document was not modified and saved by another user since you opened it, the document is saved.• If the document was modified and saved by another user since you opened it, one of the following events will occur:

– If the changes conflict, the Resolve Conflicts dialog is shown. You must decide for each conflict which version to keep, yours or the other person’s. When all conflicts are resolved, the document is saved. While you are resolving the conflicts, no other user can save the shared document.

Page 25: Libre Office Calc Lesson 5: Working with Data

Lesson 5Saving Versions

Page 26: Libre Office Calc Lesson 5: Working with Data

Saving Versions

Most documents go through many drafts. It is often useful to save new versions of a document. You can do this by saving a copy of the document [under a different name] after each revision, or by using Calc’s version feature.

Page 27: Libre Office Calc Lesson 5: Working with Data

To use version management in Calc

2) Click the Save New Version button to save a new version.3) A dialog opens where you can enter comments about this version.

1)Choose File > Versions. The Versions dialog opens.

4) After you enter your comment and click OK, the new version is included in the version list.

Page 28: Libre Office Calc Lesson 5: Working with Data

Updated version listNow when you save the file, both versions are saved in the same file. From this point you can:Open an old version – Select the version and click the Open button and a read-only copy of a previous version opens.Compare all versions – Clicking the Compare button performs an action similar to merging documents together. An Accept or Reject Changes dialog opens showing all of the changes through the different versions.Review the comments – Select a version and click the Show button to display the full comments made by yourself or other reviewers.

Page 29: Libre Office Calc Lesson 5: Working with Data

Lesson 5Calc MacrosAutomating repetitive tasks

Page 30: Libre Office Calc Lesson 5: Working with Data

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.

Page 31: Libre Office Calc Lesson 5: Working with Data

Using a macro as a function

Using the newly created Calc document CalcTestMacros.ods, enter the formula =NumberFive() [see image to the right]. Calc finds the macro and calls it.

Page 32: Libre Office Calc Lesson 5: Working with Data

Passing arguments to a macro

To illustrate a function that accepts arguments, we will write a macro that calculates the sum of its arguments that are positive —it will ignore arguments that are less than zero.

Page 33: Libre Office Calc Lesson 5: Working with Data

Arguments are passed as valuesArguments passed to a macro from Calc are always values. It is not possible to know what cells, if any, are used. For example, =PositiveSum(A3) passes the value of cell A3, and PositiveSum has no way of knowing that cell A3 was used. If you must know which cells are referenced rather than the values in the cells, pass the range as a string, parse the string, and obtain the values in the referenced cells.

Page 34: Libre Office Calc Lesson 5: Working with Data

Writing macros that act like built-in functionsAlthough Calc finds and calls macros as normal functions, they do not really behave as built-in functions. For example, macros do not appear in the function lists. It is possible to write functions that behave as regular functions by writing an Add-In. However, this is an advanced topic that is not covered here.

Page 35: Libre Office Calc Lesson 5: Working with Data

Sorting

Consider sorting the data in [image to the right]. First, sort on column B descending and then column A ascending.

Page 36: Libre Office Calc Lesson 5: Working with Data

Conclusion

This chapter provides a brief overview on how to create libraries and modules, using the macro recorder, using macros as Calc functions, and writing your own macros without the macro recorder. Each topic deserves at least one chapter, and writing your own macros for Calc could easily fill an entire book.

Page 37: Libre Office Calc Lesson 5: Working with Data

Practice 1• Create a list of your favorite

items only using text• Apply a bold format to the text• Consolidate the list of items

using the count function but place the results in Column B row 1

• Group rows 1-3• Share this document to

Stephanie Jones with Contoso (company) at 312-221-5555. Her title is Senior Executive in Rosebud Pennsylvania 20265

• Ungroup the grouped rows

• Select AutoOutline• Save

Page 38: Libre Office Calc Lesson 5: Working with Data

Practice 2• Calculate the subtotals

for column A with the function of count• Chose the 2nd Group

and chose column B with a sum function• Enable the option to

Page break between groups• Click ok

• Collapse the first row• Create a scenario for

Sheet1 within the Column A and Column B• Display light green line

for scenarios• Apply the style of

Heading 2 to the first cell in the active spreadsheet