Skip Headers

Oracle Fusion Middleware Report Designer's Guide for Oracle Business Intelligence Publisher
Release 11g (11.1.1)
Part Number E13881-01
Go to Table of Contents
Contents
Go to previous page
Previous
Go to next page
Next

Structuring Data

This chapter covers the following topics:

Working with Data Models

The Data Model diagram helps you to quickly and easily define data sets, break groups, and totals for a report based on multiple data sets.

About Multipart Unrelated Data Sets

If you do not link the data sets (or queries) you will produce a multipart unrelated query data set.

For example, in the data model below, one query selects products and another selects customers. Notice that there is no relationship between the products and customers.

the picture is described in the document text

This will produce the following data structure:

the picture is described in the document text

About Multipart Related Data Sets

In many cases, the data fetched for one part of the data set (or query) is determined by the data fetched for another part. This is often called a "master/detail," or "parent/child," relationship, and is defined with a data link between two data sets (or queries). When you run a master/detail data model, each row of the master (or parent) query will cause the detail (or child) query to be executed, retrieving only matching rows.

In the following example two data sets are linked by the element Customer ID. The Orders data set a child of the Customers data set.

the picture is described in the document text

This produces the following data structure:

the picture is described in the document text

Guidelines for Working with Data Sets

Following are recommended guidelines for building data models:

Features of the Data Model Editor

The data model editor enables you to combine data from multiple data sets into a single XML data structure. Data sets from multiple data sources can be merged either as sequential XML or at line-level to create a single combined hierarchical XML. Using the data model editor you can easily combine data from the following data set types: SQL query, OLAP (MDX query), LDAP, and Microsoft Excel.

The data model editor supports the following

The data model editor provides functions at the element level, the group level, and the global level. Note that not all data set types support all functions. See the Important Notes section that accompanies your data set type for limitations.

the picture is described in the document text

About the Interface

By default, the data sets that you created are shown in the Diagram View as separate objects.

the picture is described in the document text

The data set structure builder has three views:

Creating Links Between Data Sets

Joining and structuring data at the source into one combined data set is sometimes not possible. For example, you cannot join data at the source when data resides in disparate sources such as Microsoft SQL Server and an Oracle database. You can use the BI Publisher data engine to combine and structure data after you extract it from the data source. Even if your data is coming from the same source, if you are creating large reports or documents with potentially hundreds of thousands of rows or pages, structuring your data so that it matches the intended layout will optimize document generation.

Create a link to define a master-detail (or parent-child) relationship between two data sets. You can create links as element-level links or group-level links. The resulting, hierarchical XML data will be the same. Creating links as element-level links is the preferred method. Group-level links are provided for backward compatibility with data templates from earlier versions of BI Publisher.

A data link (or parent-child relationship) relates the results of multiple queries. A data link can establish these relationships:

About Element-Level Links

Element-level links create a bind (join) between two data sets and define a master-detail (parent-child) relationship between them. This is the preferred method of defining master detail relationships between data sets. The simplest way to link data sets is by creating element-level links because they do not require you to code a join between the two data sets through a bind variable.

About Group-Level Links

Group level links also determine the way data sets are structured as hierarchical XML, but lack the join information that the data engine needs to execute the master and detail queries. When you define a group-level link, you must also update your query with a link between the two data sets through a unique bind variable.

Creating Element-Level Links

Link data sets to define a master-detail (or parent-child) relationship between two data sets. Defining an element-level link enables you to establish the binding between the elements of the master and detail data sets.

To define an element-level link:

Deleting Element-Level Links

To delete an element link:

  1. Pause your cursor over the element connector to display the linked element names and the delete button.

  2. Click the delete button.

Or, alternatively:

  1. Open the element action menu for either element and click Delete Link.

Creating Group-Level Links

A group-level link defines a master-detail relationship between two data sets. The following figure shows two data sets with a group-level link defined. Next to the data sets the resulting XML data structure is shown.

the picture is described in the document text

To define a group-level link:

  1. In the parent group, click the View Actions menu (in the upper right corner of the object).

  2. Click Create Group Link.

    Actions Menu

    the picture is described in the document text

  3. In the Create Group Link dialog, select the Child Group from the list and click OK.

    the picture is described in the document text

  4. Click the View Actions menu and then click Edit Data Set to add the bind variables to your query.

    Example:

    Data Set: DEPT Data Set: EMP
    Select    DEPT.DEPTNO as DEPTID,
    	    DEPT.DNAME as DNAME,
    	    DEPT.LOC as LOC 
    from	 OE.DEPT DEPT
    
    Selec	t    EMP.EMPNO as EMPNO,
    	    EMP.ENAME as ENAME,
    	    EMP.JOB as JOB,
    	    EMP.MGR as MGR,
    	    EMP.HIREDATE as HIREDATE,
    	    EMP.SAL as SAL,
    	    EMP.COMM as COMM,
    	    EMP.DEPTNO as DEPTNO 
    from	  OE.EMP EMP 
    where   DEPTNO=:DEPTID
    

Important: A unique bind variable must be defined in the child query.

Deleting Group-Level Links

To delete a group link:

  1. In the parent group, click the View Actions menu (in the upper right corner of the object).

  2. Click Delete Group Link.

  3. In the Delete Group Link dialog, select the Child Group from the list and click OK.

Creating Subgroups

In addition to creating parent-child structures by linking two data sets, you can also group elements in the same data set by other elements. This might be helpful if your query returns data that has header data repeated for each detail row. By creating a subgroup you can shape the XML data for better more efficient document generation.

To Create a Subgroup:

  1. Select the element by which you want to group the other elements in the data set.

  2. Click the element action menu icon to open the menu and select Group by.

    the picture is described in the document text

    This creates a new group within the displayed data set. The following figure shows the G_3 data set grouped by the element COMPANY. This creates a new group called G_4, that contains the other four elements in the data set. The figure shows how the grouped data set is displayed in the Diagram View along with the structure.

    the picture is described in the document text

    Note that the you can perform any of the group actions on the new group you have created.

To Remove a Subgroup:

On the group's title bar, click View Actions and then click Ungroup.

Moving an Element Between a Parent Group and a Child Group

Once you have created a group within your data set, two new options display on the element action menu that enable you to move elements between the parent and child groups.

For the element you wish to move, click the element action icon to open the menu. If the element is in the parent group and you wish to move it to the child group select Move this element to Child Group.

If the element is in the child group and you wish to move it to the parent group select Move this element to Parent Group. In the following figure, the element action menu for OFFICE_DSC displays the option to move the element to the parent group.

the picture is described in the document text

Important: Be careful with moving an element as it can have dependency on other elements.

Creating Group-Level Aggregate Elements

You can use the data model editor to aggregate data at the group or report level. For example, if you group sales data by Customer Name, you can aggregate sales to get a subtotal for each customer’s sales. Note that you can only aggregate data for at the parent level for a child element.

The aggregate functions are:

To create group-level aggregate elements

  1. Drag the element to the Drop here for aggregate function field in the parent group.

    The following figure shows the element SALARY being dragged to the aggregate function bar of the G_DEPT group.

    the picture is described in the document text

    Once you drop the element, a new element is created in the parent group. By default, the Count function is applied. The icon next to the name of the new aggregate element indicates the function. Pause your cursor over the icon to display the function.

    The following figure shows the new aggregate element, CS_1. with the default Count function defined.

    the picture is described in the document text

  2. To change the function: Click the function icon to view a list of available functions and choose from the list.

    the picture is described in the document text

  3. If you wish to rename the element or update other properties, click the element's Action menu icon. On the menu, click Properties. The Properties dialog is shown in the following figure:

    the picture is described in the document text

    Important: Be careful when renaming an element as it can have dependency on other elements.

    Set the following properties as needed:

    Property Description
    Column Name The internal name assigned to the element by the BI Publisher data model editor. This name cannot be updated.
    Alias (XML Tag Name) BI Publisher assigns a default tag name that the element will have in the XML data file. You can update this tag name if you want a more meaningful name within the data file.
    Display Name The Display Name appears in the report design tools. Update this name to be meaningful to your business users.
    Function If you have not already chosen the desired function, you can select it from the list here.
    Data Type BI Publisher assigns a default data type of Integer or Double depending on the function. Some functions also provide the option of Float.
    Value if Null If the value returned from the function is null, you can supply a default value here to prevent having a null in your data.
    Do Not Reset By default, the function resets at the group level. For example, if your data set is grouped by DEPARTMENT_ID, and you have defined a sum function for SALARY, then the sum will be reset for each group of DEPARTMENT_ID data, giving you the sum of SALARY for that department only. If instead you want the function to reset only at the global level, and not at the group level, select Do Not Reset. This will create a running total of SALARY for all departments. Note that this property is for group level functions only.

Creating Group Filters

Filters enable you to conditionally remove records selected by your queries. Groups can have two types of filters:

To Create a Group Filter

  1. Click the View Actions menu and select Create Group Filter.

  2. This displays the Edit Group Filter dialog:

    the picture is described in the document text

  3. Choose the Group Filter Type: Expression or PL/SQL.

    Note: For PL/SQL filters, you must first specify the PL/SQL Package as the Oracle DB Default Package in the data model properties. See Setting Data Model Properties.

  4. Enter the Filter:

After you have added the group filter, the data set object displays the filter indicator, as shown in the following figure:

the picture is described in the document text

To Edit or Delete a Group Filter

  1. Click the data set View Actions menu.

  2. Choose the appropriate action:

Performing Element-Level Functions

You can perform the following functions at the element level:

Setting Element Properties

You can set properties for individual elements. Note that these properties are also updateable from the Structure View. If you need to update multiple element properties, it may be more efficient to use the Structure View. See Using the Structure View to Edit Data Structures.

To set element-level properties using the element dialog:

  1. Click the element's action menu icon. From the menu, select Properties. The Properties dialog is shown in the following figure:

    the picture is described in the document text

  2. Set the following properties as needed:

    Property Description
    Alias BI Publisher assigns a default tag name that the element will have in the XML data file. You can update this tag name if you want a more meaningful name within the data file.
    Display Name The Display Name appears in the report design tools. Update this name to be meaningful to your business users.
    Data Type BI Publisher assigns a default data type of Integer or Double depending on the function. Some functions also provide the option of Float.
    Sort Order You can sort XML data in a group by one or more elements. For example, if in a data set employees are grouped by department and manager, you can sort the XML data by department. Within each department you can group and sort data by manager, and within each manager subgroup, employees can be sorted by salary. If the element is not in a parent group, the Sort Order property will not be available.
    Value if Null If the value returned from the function is null, you can supply a default value here to prevent having a null in your data.

Sorting Data

Sorting is supported for parent group break columns only. For example, if a data set of employees is grouped by department and manager, you can sort the XML data by department. Within each department you can group and sort data by manager. If you know how the data should be sorted in the final report, you specify sorting at data generation time to optimize document generation.

To apply a sort order to a group:

  1. Click the action menu icon of the element you want to sort by. From the menu, select Properties.

  2. Select the Sort Order.

    The following figure shows the Properties dialog for the DEPARTMENT_ID element with the Sort Order list displayed.

    the picture is described in the document text

Performing Group-Level Functions

The Group Action Menu

The View Actions menu available at the group level enables you to perform the following:

the picture is described in the document text

Editing the Data Set

To edit the underlying data set, click Edit Data Set to launch the data set editor. See the appropriate section for the data set type in the chapter Creating Data Sets for more information.

Removing Elements from the Group

On the element, click the menu and then click Remove Element.

Note that you can only remove elements added as a group function (sum, count, and so on) or added as an expression.

the picture is described in the document text

Editing the Group Properties

Click the View Actions menu and select Properties.

the picture is described in the document text

Edit the Group Name and click OK.

Performing Global-Level Functions

The Global Level Functions object enables you to add elements to your report data set at the top report level. You can add the following types of elements as top-level data:

Important: If you select a data type of Integer for any calculated element and the expression returns a fraction, the data will not be truncated.

The Global Level Functions object is shown in the following figure. To add elements based on aggregate functions, drag the element to the "Drop here for aggregate function" space of the object. To add an element based on an expression or PL/SQL, choose the appropriate action from the View Actions menu.

the picture is described in the document text

Adding a Global-Level Aggregate Function

To add a global aggregate function:

  1. Drag and drop the data element from the data set to the "Drop here for aggregate function" area of the Global Level Functions object.

    For example, the following figure shows the Salary element dragged to the Global Level Functions object.

    the picture is described in the document text

  2. When you release the mouse, the data model editor assigns a default name to the aggregate element and assigns Count as the default function. Available functions are:

    To change the function, click the function icon to the left of the new element name and choose the function from the list.

    The following figure shows the function for the new global level element CS_1 being modified from Count to Average.

    the picture is described in the document text

  3. To change the default name, click the actions icon to the right of the element name and click Properties to launch the Edit Properties dialog, See Setting Element Properties for more about the properties available on this dialog.

Adding a Group-Level or Global-Level Element by Expression

Perform the following:

  1. To add a group-level element: On the Group object, click the View Actions menu and select Add Element by Expression.

    To add a global level element: On the Global Level Functions object, click the View Actions menu and select Add Element by Expression.

    the picture is described in the document text

  2. In the Add Element by Expression dialog, enter the fields.

    the picture is described in the document text

    Field Description
    Name Enter a name for this element.
    Alias Enter the tag name that the element will have in the XML data file.
    Display Name The Display Name appears in the report design tools. Enter a name that will be meaningful to your business users.
    Data Type Select from the list of data types: String, Integer, Double, Float, or Date.
  3. Enter the expression.

    Use the shuttle arrow to move the data elements required for the expression from the Available box to the Expression box.

    Click an operator to insert it in the Expression box, or choose from the function list.

    Refer to Function Reference for a description of the available functions.

  4. Click Validate Expression to validate.

Adding a Global-Level Element by PL/SQL

The PL/SQL function must return a VARCHAR data type.

  1. On the Global Level Functions object, click the View Actions menu and then click Add Element by PL/SQL.

  2. In the Add Element by PL/SQL dialog, enter the fields.

    the picture is described in the document text

    Field Description
    Name Enter a name for this element.
    Alias Enter the tag name that the element will have in the XML data file.
    Display Name The Display Name appears in the report design tools. Enter a name that will be meaningful to your business users.
    Data Type Must select String.
    Sort Order Select a sort order.
    Value if Null Enter a value to return if the value returned from the PL/SQL function is null.
  3. Select the PL/SQL package from the Available box and click the shuttle button to move the function to the Group Filter box.

Using the Structure View to Edit Your Data Structure

The Structure view enables you to preview the structure of your data model. The Data Source column displays the date elements in a hierarchical tree that you can collapse and expand. Use this view to verify the accuracy of the data model structure.

the picture is described in the document text

Renaming Elements

Use the Structure page to define user-friendly names for elements in the data model. You can rename both the XML element tag name (XML View) and the name that will display in the report layout tools (Business Name).

the picture is described in the document text

Adding Value for Null Elements

The Structure also enables you to enter a value to use for an element if the data model returns a null value for the element.

Enter the value to use in the Value if Null field for the element.

Function Reference

The following table describes the usage of supported functions available from the Add Element by Expression dialog and the Edit Group Filter dialog:

Function Description
IF operator
NOT operator
AND operator
OR operator
MAX Returns the maximum value of the element in the set.
MIN Returns the minimum value of the element in the set.
ROUND ROUND ( number [, integer ] )
returns number rounded to integer places right of the decimal point. If integer is omitted, then number is rounded to 0 places. integer can be negative to round off digits left of the decimal point. integer must be an integer.
Example:
round (2.777)
returns
3
Example:
round (2.777, 2)
returns
2.78
FLOOR FLOOR(n) returns largest integer equal to or less than n.
CEILING CEILING(n) returns smallest integer greater than or equal to n.
ABS ABS(n) returns the absolute value of n.
AVG AVG(expr) returns average value of expr.
LENGTH The LENGTH(char) functions return the length of char. LENGTH calculates length using characters as defined by the input character set. If char is null, then this function returns null.
SUM SUM(expr) returns the sum of value of expr.
NVL NVL(expr1, expr2) lets you replace null (returned as a blank) with a string in the results of a query. If expr1 is null, then NVL returns expr2. If expr1 is not null, then NVL returns expr1.
CONCAT CONCAT(char1, char2) returns char1 concatenated with char2.
STRING STRING(char1) returns char as a string data type.
SUBSTRING The substring function allows you to extract a substring from a string. The syntax for the substring function is:
substring(string, start_position, length)
string is the source string.
start_position is the position for extraction. The first position in the string is always 1.
length is the number of characters to extract.
INSTR The instr function returns the location of a substring in a string. The syntax for the instr function is:
instr(string1,string2,[start_position],[nth_appearance])
string1 is the string to search.
string2 is the substring to search for in string1.
start_position is the position in string1 where the search will start. The first position in the string is 1. If the start_position is negative, the function counts back start_position number of characters from the end of string1 and then searches towards the beginning of string1.
nth appearance is the nth appearance of string2.
DATE DATE(char) Converts char to date data type.
FORMAT_DATE The FORMAT_DATE function takes a date argument in Java date format and converts it to a to formatted string. For example,
FORMAT_DATE(HIRE_DATE, 'MM-DD-YYYY') where the value of HIRE_DATE is 1987-09-17T00:00:00.000+00:00 would return 17-Sep-1987.
FORMAT_NUMBER The FORMAT_NUMBER function takes a number argument and converts it to a string in the format specified. For example, FORMAT_NUMBER (SALES_UNITS,'9G990D000')
NUMBER NUMBER(char) converts char to a number data type.