Prerequisites for This Example Use the Report Wizard to Create a Simple Report

Building a Group Left Formula Report 14-3

8. Click Next.

9. On the Groups page, select CUSTOMER_ID and click the right arrow to move

this field to the Groups Fields list, then click Next. 10. On the Fields page, click the double right arrow button to move all of the fields to the Displayed Fields list, then click Next.

11. On the Totals page, click ORDER_TOTAL and click Sum, then click Next.

12. On the Template page, select Predefined Template and click Beige, then click

Finish to display your report output in the Paper Design view. It should look something like this: Figure 14–2 Paper Design view for the formula report

13. Save the report as formulareport_your_initials.rdf.

14.3 Create Two Formula Columns

Frequently, you want to base calculations on values in your data source. One way you can do this is by using formula columns. The steps in this section will show you how to create two formula columns that calculate the following values: Note: You can enter this query in any of the following ways: ■ Copy and paste the code from the provided text file called formula_code.txt into the Data Source definition field. ■ Click Query Builder to build the query without entering any code manually. ■ Type the code in the Data Source definition field. Note: If you are not already connected to a database, you will be prompted to connect to the database when you click Query Builder or Next . Ensure that you connect to a database that has the appropriate schema for this example. Section 14.1, Prerequisites for This Example describes the sample schema requirements for this example. 14-4 Oracle Reports Users Guide to Building Reports ■ the tax on each order ■ the grand total for each customer, including tax

14.3.1 Create a formula column to calculate the tax

To create a formula column that calculates the tax: 1. In Reports Builder, click the Data Model button in the toolbar to display the Data Model view of your report. The data model should look something like this: Figure 14–3 Data Model of the Formula Report

2. Click the Formula Column tool in the tool palette, then click in the G_ORDER_ID

group under ORDER_TOTAL to create a formula column.

3. Double-click the new formula column object CF_1 to display the Property

Inspector, and set the following properties: ■ Under General Information, set the Name property to Tax. ■ Under PlaceholderFormula, click the PLSQL Formula property field to display the PLSQL Editor. 4. In the PLSQL Editor, use the template to enter the following PLSQL code: function TAXFormula return Number is tax number; begin tax := :ORDER_TOTAL .07; return tax; end;

5. Click Compile.

6. If no errors display, click Close. If errors display, verify that your code looks

exactly like the above code, paying close attention to the column names. Tip: To view the names of the tools in the tool palette and the toolbar, drag and hold your mouse over each icon and hint text will display describing the icon.