Tuesday, November 10, 2015

Step by Step creating matrix report

Building a Matrix Report

In this chapter, you will learn about matrix reports. By following the steps in this chapter, you can generate the report output shown in Figure 25-1.
Figure 25-1 Matrix report output
Description of Figure 25-1  follows 
Description of "Figure 25-1 Matrix report output" 
Concepts
  • matrix report looks like a grid. As shown by the example report above, it contains one row of labels, one column of labels, and information in a grid format that is related to both the row and column labels.
  • This sample matrix also contains three additions to the basic matrix: summaries have been added, zeroes replace non-existent values in the cells, and the cells themselves are surrounded by grid lines. Of the summaries, one sums the salaries by department, one sums them by job, and one sums them for the whole report.
  • Certain requirements exist for building matrix reports:
    • You must have at least four groups in your data model.
    • One group must be a cross product group.
    • At least two of the groups must be within the cross product group. These groups furnish the "labels" of the matrix report.
    • At least one group must be a "cell" group; that is, it must provide the information related to the labels. The values from this group fill the cells created by the matrix.
  • These requirements can be seen in the preceding example. It contains four groups--one group supplies the vertical labels (department numbers) and one group supplies the horizontal labels (job identifiers). These two groups are the children of the third group, called the cross product group, which creates the grid. The fourth group provides the values that fill in the grid.
  • Matrix reports are different from tabular reports because the number of columns is not known in advance; that is, the number of columns in your report is not determined by the number of columns you specify in your SELECT statement plus the columns you create yourself. The number of columns in your report depends on the number of values contained in the columns providing the horizontal and vertical labels. Thus, the report would automatically be extended if a new job function, called RECEPTIONIST, was added to the underlying data tables.
  • The queries used to select data for these sample matrix reports are not intended as definitive examples of matrix queries. If you are concerned with performance issues, for example, there are alternate methods of querying data that can improve the performance of a matrix report.
  • You can create matrix reports with any number of queries. Section 25.2, "Create a single-query matrix" explains how to create the matrix report using one query.Section 25.3, "Create a multiple-query matrix" explains how to create the same report using three queries. These two methods yield the same results. They are presented as options; feel free to try both methods and settle on a favorite.
  • This report uses the matrix layout style. You'll modify some default settings to ensure that the column and row labels display correctly. You'll also modify some field widths to ensure that the fields fit across the page.
  • For additional conceptual information, see Section 1.3.7, "About matrix reports",
Example Scenario
In this example, you will create report that cross tabulates salaries by job function and department. The result would be a matrix with job functions listed across the top, departments down the side, and sums of salaries in the cells. Thus, you could quickly determine the sum of all of the salaries for clerks in department 20 and compare that value to the one for all clerks in some other department.
As you build this example report, you will:
To see a sample matrix report, open the examples folder named matrix, then open the Oracle Reports example named matrix1qb.rdf. For details on how to access it, see "Accessing the Example Reports" in the Preface.

25.1 Prerequisites for this example

To build the example in this chapter, you must have access to the SCOTT sample schema provided with the Oracle Database. If you do not know if you have access to this sample schema, contact your database administrator.

25.2 Create a single-query matrix

You can build a matrix report with a single query in the data model. A single-query data model typically performs better than a multiple-query data model.
When you are creating a single-query report, such as this one, you can use the Report Wizard to create the data model and layout simultaneously.
To create a data model and layout:
  1. Launch Reports Builder (or, if already open, choose File > New > Report).
  2. In the Welcome or New Report dialog box, select Use the Report Wizard, then click OK.
  3. If the Welcome page displays, click Next.
  4. On the Report Type page, select Create Paper Layout Only, then click Next.
  5. On the Style page, type a Title for your report, select Matrix, then click Next.
  6. On the Data Source page, click SQL Query, then click Next.
  7. On the Data page, enter the following SELECT statement in the Data Source definition field:
    SELECT DEPTNO, JOB, SUM(SAL)
    FROM EMP
    GROUP BY DEPTNO, JOB
    ORDER BY DEPTNO, JOB
    

    Note:
    You can enter this query in any of the following ways:
    • Copy and paste the code from the provided text file called matrix1qb_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.
  8. Click Next.

    Note:
    If you are not already connected to a database, you will be prompted to connect to the database when you click Query Builder orNext. Ensure that you connect to a database that has the appropriate schema for this example. Section 25.1, "Prerequisites for this example" describes the sample schema requirements for this example.
  9. On the Rows page, click DEPTNO and click the right arrow (>) to move this field to the Matrix Row Fields list, then click Next.
  10. On the Columns page, click JOB and click the right arrow (>) to move this field to the Matrix Column Fields list, then click Next.
  11. On the Cell page, click SUM_SAL and click the right arrow (>) to move this field to the Matrix Cell Fields list, then click Next.

    Note:
    In this case, the query itself performs the summary through the SUM function. Hence, you should not use the Sum button in this instance.
  12. On the Totals page, click Next.
  13. On the Labels page, delete the labels for all of the fields, then click Next.
  14. On the Template page, make sure Beige is selected under Predefined Template, then click Finish to display your report output in the Paper Design view. It should look like this:
    Figure 25-2 Paper Design view for the matrix report
    Description of Figure 25-2  follows 
    Description of "Figure 25-2 Paper Design view for the matrix report" 

No comments:

Post a Comment