Creating reports

From Wiki
Revision as of 17:58, 8 April 2012 by Sancho (talk | contribs)
Jump to navigationJump to search



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.

Documentation caution.png Dynamic reports update only the data that is changed or added to a table or query. It does not show any modifications made to a table or query. For example, open the fuel economy query you just created. For the "End-Reading".”Odometer – Fuel.”Odometer” column, change the number 1 to the number 3 after creating the report below. The report will be identical before and after you make the change.


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.

Documentation caution.png All reports are based upon a single table or query. So you need first to decide what fields you want to use in the report. If you want to use fields from different tables, you must first combine these fields in a single query. Then you can create a report on this query.


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.

Top of page

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.

Top of page

Vacations table report

  1. Create a new report.
    1. Click the Reports icon in the Database list in the Automobile - OpenOffice.org window.
    2. In the Tasks list, click Use Wizard to Create Report. The Report Wizard window opens.
  2. Select the fields.
    1. Select Table: Vacations in the Tables or Queries dropdown list.
    2. 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.
    3. File:AddFieldsToRpt.png
      Adding fields to a report.
  3. Label the fields: answering the question How do you want to label the fields.
    Shorten Miscellaneous to Misc. Click Next.
  4. Since we are grouping by the date, use the > button to move the Date field to the Grouping list. Click Next.
  5. File:Grouping.png
    Grouping list
  6. Sort options.
    We do not want to do any additional sorting. Click Next.
  7. Choose layout.
    We will be using the default settings for the layout. Click Next.
  8. Documentation note.png If you feel adventurous, try selecting some of the other layout choices. After selecting a choice, drag and drop the Report Wizard window so that you can see what you have selected. (Move the cursor over the Heading of this window, and then drag and drop.)
  9. Create report.
    • Label the report: Vacation Expenses.
    • Select Static report.
  10. Click Finished.

Top of page

Vacation fuel report

  1. Create a query containing only fuel bought on the days of the vacation.
    1. Open a query in Design View.
    2. 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.
    3. Double-click these fields in the Fuel table listing: Date and FuelCost to enter them in the table at the bottom of the query.
    4. In the Criterion cell of the Date field, type the following:
    5. BETWEEN #5/25/2007# AND #5/26/2007#
      File:Qcriterion.png
      Setting the criterion for a query.
    6. Save, name, and close the query. (Suggestion: Vacation Fuel Purchases.)
    Tip.png When using dates in a query, enter them in numerical form MM/DDYYYY or DD/MM/YYYY depending upon your language's default setting for dates (my default setting is MM/DD/YYYY).
    All dates must have a # before and after it. Hence, May 25, 2007 is written #05/25/2007# or #25/5/2007depending upon your language's default setting.


  2. Open a new report.
    1. Right-click the Vacation Fuel Purchases query.
    2. Select Report Wizard from the context menu.
    Documentation note.png 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.
  3. Create the report.
    Use >> to move both fields from the Available Fields to the Fields in Report list. Click Next.
  4. Label fields.
    Add a space to FuelCost to make it Fuel Cost (two words). Click Next.
  5. Group fields.
    1. Click Date to highlight it.
    2. Use > to move the Date field to the Groupings list. Click Next.
  6. Choose layout.
    We will be making no changes in the layout. Click Next.
  7. Create report (final settings).
    1. Use the suggested name, which is the same as the query.
    2. Select Static report. Click Finish.

Top of page

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.

Tip.png 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.


File:QueryEditing.png
Appearance of query when opened for editing.
  1. Add the FuelCost field to the End-Reading query:
    1. In the Fuel table list, double-click to add FuelCost to the bottom table.
    2. Save and close the query.
    3. File:AddFieldToQ2.png
      Adding an additional field to the query.
  2. Right-click the End-Reading query and select Edit from the context menu.
  3. Add the FuelCost field from the End-Reading query to the Fuel Economy query.
    1. Right-click the Fuel Economy query and select Edit from the context menu.
    2. Double-click the FuelCost field in the End-Reading query list to the table at the bottom.
  4. Add a calculation field to the right of the FuelCost field.
    1. Type the following in the Field cell:
      "End-Reading".FuelCost/("End-Reading".Odometer - Fuel.Odometer)
    2. Type the following in the Alias cell:
      cost per mile
    Documentation note.png If you use the metric system, cost per km is the appropriate alias.
  5. Save and close the query.
  6. Open a new report.
    Right-click the Fuel Economy query and select Report Wizard.
  7. Select fields.
    Move all the fields from the Available fields to the Fields in report list. Use the >> to do so. Click Next.
  8. Label fields.
    Change FuelCost to Fuel Cost by placing a space between the words. Click Next.
  9. Group fields.
    Use > to move the Date field to the Groupings list. Click Next.
  10. Sort options: the wizard skipped this one.
  11. Choose layout.
    Accept the default. Click Next.
  12. Create the report.
    1. Change the report name to Fuel Statistics.
    2. The default setting is Dynamic report, so no change is necessary.
    3. Select Modify report layout. Click Finish.

Top of page

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.

File:BaseRptEdit.png
A report in edit mode.

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.

Top of page

Step 1: Change the date.

  1. 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.
  2. Insert > Fields > Date. This places today's date where the original date was.
  3. Change the date formating:
    1. Double-click the date field you just inserted. The Edit Fields: Document window opens (figure below).
    2. File:BaseEditFields.png
      Modifying a date field.
    3. Since this is a dynamic report, change the Select field from Date (fixed) to Date.
    4. Change the Format to what you desire. (I use the Friday, December 31, 1999 choice.) Click OK.

Top of page

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.

File:RealignCols.png
Realigned columns in a report.

Top of page

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.

  1. Right-click the cell below Quantity to open the context menu. (The cell is circled in red in the figure above.)
  2. Select Number format.
  3. In the Options section,
    1. Change the number of Decimal places to 3.
    2. Click the green checkmark. Click OK.
    3. File:NumberFormat.png
      Option section of the Number Formating window.
  4. Change the Cost per mile field.
    1. Right-click in the cell below Cost per mile.
    2. Select Number Format.
    3. In the Category list, select Currency. Click OK.
  5. Change the Fuel Cost field.
    1. Right-click in the cell below Cost per mile.
    2. Select Number Format.
    3. In the Category list, select Currency.
    4. In the Option section:
      • Set the number of decimal places to 3.
      • Click the green checkmark.
    5. Click OK.

Top of page

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:

  1. Select Tools > Extension Manager from the menu bar. In the Extension Manager dialog, click Get more extensions here....
  2. 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.
  3. 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).