Creating reports
Reports provide information found in the database in a useful way. In this they are similar to queries. Reports are generated from the database's tables or queries. They can contain all of the fields of the table or query or just a selected group of fields. Reports can be static or dynamic. Static reports contain the data in the selected fields at the time the report was created. Dynamic reports can be updated to show the latest data.
For example, a report on vacation expenses divided into categories should probably be a static report because it is based upon specific data that does not change. However, a report on the fuel data should probably be a dynamic report, because this report depends upon data that does change.
An example of this caution is creating a report on vacation expenses. Fuel costs are one part of that report as are meal costs. These values are contained in fields of two different tables: Vacations and Fuel. So this report requires creating a query.
Creating a static report
We will create a report on vacation expenses. Certain questions need to be asked before creating the report.
- What information do we want in the report?
- How do we want the information arraigned?
- What fields are required to provide this information?
- Will a query have to be created because these fields are in different tables?
- Are there any calculations required in the data before being added to the report?
The expenses for our vacation are motel, tolls, miscellaneous, breakfast, lunch, supper, snacks, and fuel. One possible report would simply list the totals of each of these expense groups. Another possible report would list the expense totals for each day of the vacation. A third possible report would list the totals for each expense group for each type of payment. (This would let us know where the money came from to pay the expenses.) At the present time, using the data from the queries in a spreadsheet is the best way to handle reports like this. In the near future, the report feature will include these abilities.
For our purposes, we will create two reports. The first one will list the expenses each day other than fuel. The second report will list the fuel costs each day.
The fields we will need for the first report from the Vacations table are: Date, Motel, Toll, Breakfast, Lunch, Supper, SnackCost, and Miscellaneous. This report will not require an additional query.
The second report involves the Fuel table. Since fuel was purchased and entered into this table at times other than during the vacation, a query needs to be created that contains only the fuel purchased during the vacation.
Vacations table report
- Create a new report.
- Click the Reports icon in the Database list in the Automobile - OpenOffice.org window.
- In the Tasks list, click Use Wizard to Create Report. The Report Wizard window opens.
- Select the fields.
- Select Table: Vacations in the Tables or Queries dropdown list.
- Use the > to move these fields from the Available fields list to the Fields in report list: Date, Motel, Tolls, Miscellaneous, Breakfast, Lunch, Supper, and SnackCost. Click Next.
- Label the fields: answering the question How do you want to label the fields.
Shorten Miscellaneous to Misc. Click Next. - Since we are grouping by the date, use the > button to move the Date field to the Grouping list. Click Next.
- Sort options.
We do not want to do any additional sorting. Click Next. - Choose layout.
We will be using the default settings for the layout. Click Next. - Create report.
- Label the report: Vacation Expenses.
- Select Static report.
- Click Finished.
Vacation fuel report
- Create a query containing only fuel bought on the days of the vacation.
- Open a query in Design View.
- Follow the steps for adding tables in [[../Creating_queries_and_reports#Step 2: Add tables.|Step 2: Add tables]] of [[../Creating_queries_and_reports#Using the Design View to create a query|Using the Design View to create a query]]. Add the Fuel table.
- Double-click these fields in the Fuel table listing: Date and FuelCost to enter them in the table at the bottom of the query.
- In the Criterion cell of the Date field, type the following:
- BETWEEN #5/25/2007# AND #5/26/2007#
- Save, name, and close the query. (Suggestion: Vacation Fuel Purchases.)
- Open a new report.
- Right-click the Vacation Fuel Purchases query.
- Select Report Wizard from the context menu.
- Create the report.
Use >> to move both fields from the Available Fields to the Fields in Report list. Click Next. - Label fields.
Add a space to FuelCost to make it Fuel Cost (two words). Click Next. - Group fields.
- Click Date to highlight it.
- Use > to move the Date field to the Groupings list. Click Next.
- Choose layout.
We will be making no changes in the layout. Click Next. - Create report (final settings).
- Use the suggested name, which is the same as the query.
- Select Static report. Click Finish.
When a new report is opened in this way, the query used to open it is automatically selected in the Tables or Queries dropdown list. |
Creating a dynamic report
We will create a report with some statistics on our fuel consumption. To do this, we have to modify two queries: End-Reading and Fuel Economy. We will be adding the FuelCost field to the End-Reading query. Then we will add the FuelCost field from the End-Reading query to the Fuel Economy query.
When opening a query to edit it, it might appear as below. If you move your cursor over the black line (circled in red), it becomes a double headed arrow. Drag and drop it to a lower position. |
- Add the FuelCost field to the End-Reading query:
- In the Fuel table list, double-click to add FuelCost to the bottom table.
- Save and close the query.
- Right-click the End-Reading query and select Edit from the context menu.
- Add the FuelCost field from the End-Reading query to the Fuel Economy query.
- Right-click the Fuel Economy query and select Edit from the context menu.
- Double-click the FuelCost field in the End-Reading query list to the table at the bottom.
- Add a calculation field to the right of the FuelCost field.
- Type the following in the Field cell:
"End-Reading".FuelCost/("End-Reading".Odometer - Fuel.Odometer) - Type the following in the Alias cell:
cost per mile - Save and close the query.
- Open a new report.
Right-click the Fuel Economy query and select Report Wizard. - Select fields.
Move all the fields from the Available fields to the Fields in report list. Use the >> to do so. Click Next. - Label fields.
Change FuelCost to Fuel Cost by placing a space between the words. Click Next. - Group fields.
Use > to move the Date field to the Groupings list. Click Next. - Sort options: the wizard skipped this one.
- Choose layout.
Accept the default. Click Next. - Create the report.
- Change the report name to Fuel Statistics.
- The default setting is Dynamic report, so no change is necessary.
- Select Modify report layout. Click Finish.
Modifying a report
At the end of the last section, we left the Fuel Statistics report open in the edit mode. We will be working on that report. These same steps can be used with any report that you open for editing.
The Author is the name you listed in Tools > Options > OpenOffice.org > User Data. The date is not correct. The columns need to be moved to the left to give a better appearance. None of the numbers are correct, but their only purpose is to show the number of decimal places.
Step 1: Change the date.
- Click to the right of the date (4/26/20) so that the cursor is next to the field. Use the Backspace key to erase the date.
- Insert > Fields > Date. This places today's date where the original date was.
- Change the date formating:
- Double-click the date field you just inserted. The Edit Fields: Document window opens (figure below).
- Since this is a dynamic report, change the Select field from Date (fixed) to Date.
- Change the Format to what you desire. (I use the Friday, December 31, 1999 choice.) Click OK.
Step 2: Change the column widths.
The column widths can be changed by moving the cursor over the right border of each column so that it becomes a double-headed arrow. Then drag and drop it where you want it. This has to be done for each column in each table in the report. This can also be done with the last column on the right even though there is no black border. It should now look something like the figure below.
Step 3: Change the number formating in the cells.
The fuel quantity should have three decimal places. The Begin, End, and Distance should have one decimal place. Fuel Cost should be currency and have two decimal places, and Cost per mile should have three decimal places.
- Right-click the cell below Quantity to open the context menu. (The cell is circled in red in the figure above.)
- Select Number format.
- In the Options section,
- Change the number of Decimal places to 3.
- Click the green checkmark. Click OK.
- Change the Cost per mile field.
- Right-click in the cell below Cost per mile.
- Select Number Format.
- In the Category list, select Currency. Click OK.
- Change the Fuel Cost field.
- Right-click in the cell below Cost per mile.
- Select Number Format.
- In the Category list, select Currency.
- In the Option section:
- Set the number of decimal places to 3.
- Click the green checkmark.
- Click OK.
Step 4: Save and close the report.
Double-click the report. It should now look like the figure below.
More ways to create reports
An extension is available to assist in report creation. Sun Report Builder creates stylish, complex database reports. You can define group and page headers, group and page footers, and calculation fields. It is available from [1].
To install this extension, follow these steps:
- Select Tools > Extension Manager from the menu bar. In the Extension Manager dialog, click Get more extensions here....
- The OOo extensions page opens in your browser window. Find and select the extension you want to install and follow the prompts to install it. During installation, you will be asked to accept a license agreement.
- When the installation is complete, the extension is listed in the Extension Manager dialog.
For more about extensions, see Chapter 14 (Customizing OpenOffice.org).
Content on this page is licensed under the Creative Common Attribution 3.0 license (CC-BY). |