Click Close to close the Impact dialog when you have finished reviewing the

10-24 Oracle Fusion Middleware Administrators Guide for Oracle Business Intelligence Discoverer views, one for each master-detail aggregation, and then combines the results of the outer query. The following example shows the SQL that Discoverer uses to return the correct results: SELECT inACC as Name, SUMinSalesSum as SALES_SUM, ,SUMinBudgetSum as BUDGET__ SUM, FROM SELECT masterID AS OutMasterIDSales, SUMSalesDetailsSales AS inSalesSum FROM SELECT ID AS masterID, NAME AS masterName FROM ACCOUNT INLineAccount, SELECT ID AS SalesDetailId, ACCID AS SalesDetailAccID, SALES AS SalesDetailsSales FROM SALES INLineSales WHEREmasterID = SalesDetailAccID+ GROUP BY masterID inner1, SELECT masterID AS OutMasterIDBudget, SUMBudgetDetailBudget AS inBudgetSum, masterName AS inACC FROM SELECT ID AS masterID, NAME AS masterName FROM ACCOUNT INLineAccount, SELECT ID AS BudgetDetailId, ACCID AS BudgetDetailAccID, BUDGET AS BudgetDetailsSales FROM BUDGET INLineBudget WHEREmasterID = BudgetDetailAccID+ GROUP BY masterName, masterID inner2 WHERE OutMasterIDBudget = OutMasterIDSales GROUP BY inACC The result is correct because each sale and each budget is summed individually one for each master-detail aggregation and is then combined with a join based on the master keys. Producing incorrect results using a straightforward SQL statement To answer the question, What is the total sales and total budget by account?, you might consider using a staightforward SQL statement such as the following: SELECT Account.Name, SUMsales, SUMbudget FROM Account, Sales, Budget Where Account.id=Sales.accid AND Account.id=Budget.accid GROUP BY Account.Name This straightforward SQL statement returns incorrect results, as shown below: Although the results are relationally correct, they are obviously wrong. For example, the results indicate that the total sales figure for Account 1 is 800 but you can see from the SALES table that the total sales figure for Account 1 is 400 that is, 100+100+200. Account Sales Budget Account 1 800 1200 Account 2 130 200 Account 3 600 750 Account 4 600 600 Creating and Maintaining Joins 10-25 The incorrect results are based on a single query in which the tables are first joined together in a temporary table, and then the aggregation is performed. However, this approach causes the aggregates to be summed incorrectly multiple times. What to do if you set up a fan trap inside a complex folder Discoverer warns about fan trap join configurations in complex folders by displaying a message indicating that an invalid join configuration exists. To make sure that Discoverer returns correct results for complex folders, you can edit the Formula property of the detail item and explicitly specify the aggregate formula. For example, you might set the Formula property of a Sales item in a complex folder, from Sales Fact.Sales to SUMSales Facts.Sales, as shown below: Figure 10–19 Example of an aggregate formula specified for an item in a complex folder What to do if you have a data type mismatch in a join Discoverer does not allow joins between items of different data types for example, varchar, numeric, or date. However, if you have upgraded from a previous version of Discoverer, an existing join might already exist between mismatched data types. If a join exists between two items with mismatched data types, Discoverer runs the query but displays an error message and does not complete the query. Discoverer also displays an error message if you try to edit a join that contains items that have mismatched data types. You can create a join between two items that have mismatched data types by following the steps below: ■ create a new item based on the first mismatched item and use conversion functions for example, to_char, to_date, to_number to make the new item’s data type compatible with the second item ■ create a join between the new item and the second item For more information, see Example of how to create a join between two items that have mismatched data types . 10-26 Oracle Fusion Middleware Administrators Guide for Oracle Business Intelligence Discoverer Example of how to create a join between two items that have mismatched data types In this example, you want to create a join between the Calendar Date folder and the Store and Sales Detail folder, using: ■ the Day of Week item from the Calendar Date folder ■ the Transaction Date item from the Store and Sales Detail folder These two items have mismatched data types, as follows: ■ the Day of Week item’s data type is varchar ■ the Transaction Date item’s data type is date To create a join between the two folders using these two items, you must perform the following steps: ■ Step 1: Create a new item that converts the Day of Week item from a varchar to a date data type ■ Step 2: Create a join using the new item Step 1: Create a new item that converts the Day of Week item from a varchar to a date data type The first step is to create a new item that converts the Day of Week item from varchar to a date data type as follows:

1.

Select the Calendar Date folder from the Video Store Tutorial business area. 2. Choose Insert | Item to display the New Item dialog .

3. Type New Day of Week in the Item Name field.

4. Select the Functions option to display the function folders.

5. Click the + symbol next to the Conversion folder to display the conversion functions. 6. Select the TO_DATE function and click PASTE to paste the TO_DATE function into the Calculation field for the new item.

7. Replace the text in the Calculation field between the brackets of the TO_DATE

function with the following text: Day of Week,Day The Calculation field now displays the following text: TO_DATEDay of Week,Day 8. Click OK to create the new item. You have now created a new item that is based on the Day of Week varchar item and that has been converted to a date data type. Step 2: Create a join using the new item Having created a new calculated item of the correct data type, the next step is to join the new item to the Transaction Date item from the Store and Sales Details folder, as follows:

1.

Select the New Day of Week item from the Calendar Date folder. 2. Choose Insert | Join to display the Join Wizard: Step 1 dialog . 3. Click the Detail Items drop down list to display the New Join dialog . Creating and Maintaining Joins 10-27 The New Join dialog enables you to select the detail folder and item for the new join. 4. Click the + symbol next to the Store and Sales Details folder to expand the folder’s items. 5. Select the Transaction Date item and click OK to close the New Join dialog. 6. Click Next to display the Join Wizard: Step 2 dialog . 7. Click Finish to accept the default join options and close the Join Wizard: Step 2 dialog. Discoverer is able to join the Calendar Date folder with the Store and Sales Details folder using the New Day of Week item and the Transaction Date item because both items have the same data type. 10-28 Oracle Fusion Middleware Administrators Guide for Oracle Business Intelligence Discoverer

11

Creating and Maintaining Calculated Items 11-1

11

Creating and Maintaining Calculated Items This chapter explains how to create and maintain calculated items using Discoverer Administrator, and contains the following topics: ■ What are calculated items? ■ What are derived items? ■ What are aggregate calculated items? ■ What restrictions apply to aggregate calculated items? ■ What are the differences in behavior between analytic functions and aggregate calculated items? ■ What are aggregate derived items? ■ Example of an aggregate derived item ■ How to create calculated items ■ How to edit calculated item properties ■ How to edit calculated items ■ How to delete calculated items ■ How to create a calculated item that enables end users to drill out from one worksheet to display another worksheet in Discoverer Viewer ■ Why do you need PLSQL functions? ■ What are custom PLSQL functions? ■ About registering custom PLSQL functions ■ How to register custom PLSQL functions automatically ■ How to register custom PLSQL functions manually What are calculated items? Calculated items are items that use a formula to derive data for the item. Calculated items enable Discoverer end users to apply business calculations to the data. For example, typical business calculations might include: ■ profit margins ■ average revenues per month ■ expected sales