Documente Academic
Documente Profesional
Documente Cultură
25
Building a Matrix Report
Figure 25-1 Matrix report output
A 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. (Matrix reports are also sometimes referred to as "crosstab" reports.)
Our 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.
Concepts
Example Scenario
Suppose you want to 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.
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.
Table 25-1 Features demonstrated in this example
Feature Location
Create a matrix report with a single-query data Section 25.2, "Create a single-query matrix"
model
Create a matrix report with a multiple-query data Section 25.3, "Create a multiple-query matrix"
model
Add summaries for rows and columns Section 25.4, "Add summaries to the single-query
matrix"
Substitute zeroes for blanks Section 25.6, "Add zeroes in place of blanks"
Add grid lines around cells Section 25.7, "Add a grid"
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.
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:
8. SELECT DEPTNO, JOB, SUM(SAL)
9. FROM EMP
10. GROUP BY DEPTNO, JOB
11. ORDER BY DEPTNO, JOB
12.
Note:
o Copy and paste the code from the provided text file
called matrix1qb_code.txt into the Data Source definition field.
o Click Query Builder to build the query without entering any code manually.
o Type the code in the Data Source definition field.
Click Next.
Note:
If you are not already connected to a database, you will be prompted to connect to the
database when you click Next. 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 via the SUM function. Hence, you
should not use the SUM button in this instance.
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:
In this case, it is easier to create the data model and layout separately. Hence, we will create an
empty report first, then add the queries, and then create the layouts.
25.3.2 Create a data model with a cross product and a data link
When you create a report with multiple queries, it is typically easier to create all of the queries
with the Data Wizard first and then create the layouts with the Report Wizard.
1. In the Data Model view, choose Insert > Query to display the Data Wizard.
3. On the Query page, type Q_Dept for the Query name, then click Next.
4. On the Data Source page, click SQL Query, then click Next.
If you click Query Builder, you can build the query without entering any code
manually.
6. Click Next.
Note:
If you are not already connected to a database, you will be prompted to connect to the
database when you click Next. 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.
8. Click Finish to display your first query in the Data Model view.
9. Repeat the steps above for a second query, but this time name your query Q_Job and use
the following SELECT statement:
10. SELECT DISTINCT JOB
11. FROM EMP
12.
10. Again, repeat the steps above for a third query, but this time name your
query Q_Matrix and use the following SELECT statement:
11. SELECT DEPTNO, JOB, SUM(SAL)
12. FROM EMP
13. GROUP BY DEPTNO, JOB
14. ORDER BY DEPTNO, JOB
15.
1. In the Data Model view, click the Cross Product tool in the tool palette.
2. Drag a box around G_DEPTNO and G_JOB. When you release the mouse button, the
cross product group is created. Ensure that it completely surrounds both groups.
Figure 25-4 Three query data model with cross product group
1. In the Data Model view, click the Data Link tool in the tool palette.
2. Click and drag from the DEPTNO column in the G_DEPTNO group to
the DEPTNO1 column in the G_DEPTNO1 group.
3. Repeat steps 1 and 2, but this time drag the link between the JOB column
in G_JOB and JOB1 in G_DEPTNO1.
Figure 25-5 Three query data model with cross product group and data links
Once your data model is complete, you need to create a layout for the data objects to display in
the report output.
1. In the Data Model view, right-click on the canvas, then choose Report Wizard.
2. In the Report Wizard, on the Report Type page, select Create Paper Layout only.
5. On the Fields page, ensure that only the following columns appear in the Displayed
Fields list:
o DEPTNO
o JOB
o SUM_SAL
6. On the Labels page, delete the labels for all of the fields.
7. 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:
The steps below describe the procedure for adding summaries to the single-query matrix.
Although you can use the Report Wizard to add summaries to a single-query matrix,
you cannot use this method for a multiquery matrix.
3. On the Totals page, click SUM_SAL in the Available Fields list, then click Sum.
Tip:
You may have to use the arrows to make the Totals tab visible.
4. Click Finish to preview your report output in the Paper Design view.
Note:
When your new layout is created, you should notice a couple of things. First, at the
bottom of each column of the matrix, you should now see a summary of that column's
values. The report is also probably more than one page long now. Because of the width
of the layout, the summaries for the departments cannot fit on the page with the rest of
the matrix. Hence, the department summaries and the report summary overflow to the
next page. Go to the second page of the report and you will see the department
summaries and the report summary.
1. On the first page of the report, click one of the cell values. Notice that all of the values are
immediately selected, indicating that you can change their properties simultaneously.
2. Shift click on one of the summary values at the bottom of a column of the matrix.
3. Click the Currency button in the toolbar. A currency symbol immediately appears next to
all of the values.
4. Click the Add Decimal Place button in the toolbar twice. Two decimal places are added
to the right of the decimal point.
5. Resize the fields. Click and drag the rightmost handle of the cell value under
the SALESMAN label about 0.5 inches to the left. After you complete this operation, the
department summaries from the second page should move onto the first page.
9. Click one of the department summaries at the end of a row in the matrix. All of the
department summaries are immediately selected.
11. Use the left arrow key to move these summaries to the left until they are approximately
flush with the SALESMAN column in the matrix.
12. Click the Currency button in the toolbar. A currency symbol immediately appears next to
all of the values.
13. Click the Add Decimal Place button in the toolbar twice. Two decimal places are added
to the right of the decimal point.
14. Resize the fields. Click and drag the rightmost handle of one of the selected fields about
0.5 inches to the left.
Figure 25-9 Matrix report in Paper Design view with monetary values formatted
The matrix displays this juxtaposition of values using a grid-like format. If the two categories
have nothing in common, the grid at that point is empty. The matrix appears to be full of
"holes". You can fill the holes using boilerplate text.
Note:
Do not confuse empty spaces in the grid with null values. A null value is an actual
value fetched from the database. The spaces in a matrix report are empty because
nothing has been fetched to fill them.
1. Open the matrix report to which you previously added the summaries.
2. In the Object Navigator, double-click the view icon next to the Paper Layout node to
display the Paper Layout view.
Tip:
The steps that follow require some precision in the placement of objects. Hence, you
may want to magnify the view to make the process easier. Click the Magnify tool and
then click somewhere in the Paper Layout view. Repeat as many times as necessary.
3. In the Paper Layout view, click the Confine On and Flex On buttons in the toolbar to turn
both modes on.
4. From the font lists in the tool bar, choose Arial (Western), point size 10.
7. Click on top of the F_SUM_SAL field about 0.75 inches from its right edge. Your
objective is to create an object right on top of F_SUM_SAL.
10.
10. In the Object Navigator, type B_1 in the Find field. You will be taken to the object you
just created. If you are viewing the Object Navigator in Ownership View ( View > Change
View > Ownership View), you should see B_1 underneath R_G_SUM_SAL and on the same
level as F_SUM_SAL.
Tip:
If B_1 does not appear underneath R_G_SUM_SAL, return to the Paper Layout view,
delete B_1 and try again.
11. Click R_G_SUM_SAL and then Ctrl-click on F_SUM_SAL so that they are both selected
and B_1 is deselected.
Figure 25-11 Object Navigator with repeating frame and field selected
Text description of the illustration matrix_on2.gif
12. Click on the title bar of the Report Editor to make it the active window.
13. Click the Confine Off button in the toolbar to turn Confine mode off.
Tip:
After this operation, B_1 should appear just above R_G_SUM_SAL, as a peer rather
than a child of R_G_SUM_SAL. If B_1 is still appearing as a child under
R_G_SUM_SAL, repeat steps 11 through 14 until it is no longer appearing as a child
of R_G_SUM_SAL.
15. In the Paper Layout view, click the Confine On button in the toolbar to turn Confine
mode back on again.
16. Click the Paper Design button in the toolbar to display the Paper Design view.
Tip:
If the $0.00 is not quite aligning with the other monetary values around it, select it and
use the arrow keys to move it to the desired location.
1. Open the matrix report which you previously modified to show zeroes instead of blanks.
2. In the Object Navigator, double-click the view icon next to the Paper Layout node to
display the Paper Layout view.
3. In the Object Navigator, choose View > Change Views > Object Type View.
4. Select all of the following objects in the Object Navigator using Ctrl-click:
o F_SumSUM_SALPerDEPTNO
o F_SumSUM_SALPerJOB
o F_SumSUM_SALPerReport
o F_SUM_SAL
o B_1
5. Click on the title bar of Paper Layout view to make it the active window.
6. In the Paper Layout view, click the Line Color tool in the tool palette, and choose black.
7. Click the Paper Design button in the toolbar to display the Paper Design view. You
should now see a grid around all of the cells in your matrix.
25.8 Summary
Congratulations! You have successfully created a matrix report. You now know how to:
For more information on any of the wizards, views, or properties used in this example, refer to
the Reports Builder Online Help, which you can access in two ways:
Note:
You can replace your Reports Builder online help with the most recent update by
downloading the latest online help set available on the Oracle Technology Network
(http://otn.oracle.com/docs/products/reports/). Instructions for replacing
your help file are included in the readme.txt in the download file.