## Lesson 2: Performing data analysis on ad hoc reports

Data analysis is the ability to look at the data in a report in another way. That is, to add a cube element to an existing report, to pivot data components, and to convert data components.

In this lesson, we perform these data analysis tasks on the reports we created in Lesson 1.

This lesson contains the following tasks:

- Task 1: Analyze data of a banded object
- Task 2: Analyze data of a table
- Task 3: Analyze data of a crosstab
- Task 4: Analyze data of a chart

### Task 1: Analyze data of a banded object

1. Click CustomerOrders from the Go To drop-down list on the toolbar to switch to this report.

Now, we want to make the records in each Employee Name group further grouped in every possible territory, and to know whether the payment for each order has been received or not.

2. Close the Toolbox panel and then click Menu > View > Resource View to display the Resource View panel.
3. In the panel, expand the Dimensions category, drag Territory to the banded object and drop it as the mouse pointer moves below the Employee Name group header and a tip Group Header appears:

4. Drag the Payment Received field in the Detail Information category to the detail panel of the banded object:

   Now the report looks as follows:

Next, we will do some adjustments to improve the appearance of the report.

1. Right-click the label Customer Orders Report and select Properties from the shortcut menu. Then in the Label Properties dialog, go to the Font tab, check the Bold option and then click OK.
2. Right-click the Payment Received label and choose Properties from the shortcut menu.
3. In the General tab of the Label Properties dialog, set the Width property to 1.15, and then click OK. This is to make the label text displayed completely.

4. Right-click any value of the Payment Received field and select Properties from the shortcut menu.

5. In the Font tab of the Data Field Properties dialog, set the Horizontal Alignment property to right, then click OK.
6. Right-click any value of the Order Date field and select Properties from the shortcut menu.
7. In the General tab of the Data Field Properties dialog, set the Format property to MM/dd/yyyy and click OK.

There are two group levels in the banded object, so we will change the background color of the Territory group in order to distinguish the two levels.

1. Right-click the group header panel of the Territory group, which is shown as GroupHeaderPanel1 on the shortcut menu, and click Properties on the menu.
2. In the General tab of the Banded Panel Properties dialog, set the Background property to #668cb2, and then click OK to confirm.

Click the Next button on the toolbar (or just simply scroll down the mouse wheel) to view page 2 and repeat this to view the next pages, and you may find the interval between every two Territory groups, which is the group footer panel. So next, we will make it invisible.

1. Right-click the GroupFooterPanel1 which is footer panel of the Territory group and select Properties from the shortcut menu.
2. In the General tab of the Banded Panel Properties dialog, set the Height property to 0 and click OK.

   Now the report looks as follows:

Next, we will do some sorting and filtering on the report. We would like to sort the records in each group by Line Item Total ascendingly, and filter the records to only show orders without a payment received.

1. Click the Sort button on the toolbar to open the Sort dialog.
2. In the Sort dialog, select BandedObject from the Sort in Scope drop-down list, choose TOTAL from the field drop-down list, keep the sorting manner as Ascending, and then click OK to apply the settings.

3. Right-click any value of the Payment Received field, and on the shortcut menu, click Filter > false.

   After doing the sorting and filtering, the report looks as follows:

In the above two steps, we used two ways to sort and filter the report results: one by dialog and the other by right-click menu command. In fact, both sorting and filtering can be achieved by either way.

We have defined two grouping levels in the banded report: one by Employee Name and the other by Territory. Next, we will change one of the grouping criteria: grouping the banded object by Country instead of Territory.

1. Right-click any of the Territory value ("Southeast, USA" for example) and click Drill To > Country on the shortcut menu.

   The report result finally changes to:

2. Click the Save button on the toolbar to save the changes.

### Task 2: Analyze data of a table

1. Select CurrentCustomers from the Go To drop-down list on the toolbar to switch to this report.

First, we want to remove the zip information from the table as we think it is not required.

1. Right-click the Zip label and select Remove Column from the shortcut menu to delete the Zip label and its corresponding DBField.

Next, we will add a group Region, and make its level higher than the existing Country group.

1. Make sure the Resource View panel is shown, then drag Region in the Dimensions category from the panel to the upper part of any Country group header:

Next we want to add some detail fields to the table.

1. Drag State in the Dimensions category from the Resource View panel to the right part of the Phone column and drop it when a blue line occurs along the right boundary of the column.

2. Drag Customer Address in the Detail Information category to the right of the State column in the same way.

However, we now consider the state information is not very useful because we will care more about the city information. So we can overwrite State with City.

1. Drag City in the Dimensions category from the Resource View panel to the State column label and drop it when this title is highlighted:

   The report result becomes:

2. Resize the Customer Name column by dragging the boundary to the right of the column to make all the customer names in the column displayed entirely.

3. Repeat the resizing step for the Phone, City, and Customer Address columns.

   The report result finally changes to:

4. Click the Save button on the toolbar to save the changes.

### Task 3: Analyze data of a crosstab

1. Click Sales from the Go To drop-down list on the toolbar to switch to the report Sales, which contains a crosstab and a chart.
2. Right-click USA in the row header, and select Drill to By Value > Territory to obtain a more detailed view of USA information.

   The report is regenerated to show data of territories in the USA:

Next, we want to further view the details about the territory Northeast of USA. Because Territory is a level predefined in the hierarchy Geography of BusinessCubeDemo, we can drill it down to the State level.

1. Right-click Southeast, USA in the row header, and select Drill Down > State from the shortcut menu.

   Now, only data of states in the Southeast territory is displayed:

We can further drill any State down to City in this way if necessary. Here, let's leave the crosstab as it is.

Next, we want to pivot the crosstab, namely interchange the rows and columns.

1. Click any cell of the crosstab, then click Menu > Report > Rotate Crosstab, and the crosstab changes to:

2. Right-click the total value for any state and select Properties from the shortcut menu.
3. In the General tab of the Data Field Properties dialog, set the Format property to $#,###.##, then click OK to confirm.
4. Right-click the total value for any employee and do the same, and also for the grand total (329,477.54).
5. Resize the row header to make sure all the employee names can be shown completely (if the resizing arrows does not appear when you move the mouse pointer to the boundary of the row header, you can resize the height of the rows a little bit first).

   The report result finally changes to:

6. Click the Save button on the toolbar to save the changes.

### Task 4: Analyze data of a chart

Now let's focus on the chart at the lower part of the Sales report. In JReport, a chart can be converted to crosstab, and vice versa. So we will convert the chart to a crosstab first.

1. Click the background of the chart to select it, then click Menu > Report > To Crosstab.
2. In the Display tab of the To Crosstab dialog, add Sales Year to the Columns box, Category to the Rows box, and Total Sales to the Aggregates box, then click Next.

3. In the Style tab, set the crosstab style as ClassicBlue, and then click OK. The chart is successfully converted to a crosstab.

Now, we want to edit the predefined filter to show any category which is not Straights & Blends.

1. Right-click the blank area formed by the row header and column header of the crosstab, then click Query Filter on the shortcut menu.
2. In the Query Filter dialog, click the Edit button, then modify the value of the filter condition to 'Exotic'. Click OK to apply the changes.

   We can find that after editing a predefined filter of a business cube in JReport Web, it is then saved as a user defined filter in the business cube.

   The crosstab now becomes:

Next, we want to return the crosstab to a chart, and change the chart type to pie chart.

1. Click the menu command Menu > Edit > Undo to cancel the operation of converting chart to crosstab.

   We can also select any cell of the crosstab and click Menu > Report > To Chart to convert the crosstab to chart.

2. Right-click the chart, and on the shortcut menu, click Chart Type > Pie > Clustered Pie:

   The chart now appears as follows:

Next, we will format the chart.

1. Right-click the platform of the chart and select Format Chart from the shortcut menu.
2. In the Chart Type tab of Chart Definition dialog, select Bench from the Chart Type box, and select the Bench 3-D thumbnail.
3. Click the Display tab, select Sales Year in the Category box and click to remove it; then expand the Dimensions category in the Resources box and add Category to the Category box.
4. Remove Category from the Series box and add Sales Year in the Dimensions category to the box.
5. Add Total Sales in the Measures category to the Show Values box.

6. Click the Style tab, apply the Classic style to the chart, then click OK to apply the changes.

   The chart now appears as follows:

7. Right-click the chart, select Format Paper from the shortcut menu.
8. In the Format Paper dialog, click the Coordinate tab, set Scale X to 90, Scale Y to 80 and Angle Y to 8, then switch to the Graph tab and set Bar Width to 30. Click OK to confirm.
9. Right-click the chart, and on the shortcut menu, select Format Platform.
10. In the Format Platform dialog, click the Border tab, set Border Type to solid and Color to #66ccff, then click the Data tab, set Sort Category to ascending and Sort Series to descending. Click OK to confirm.

    Finally the chart looks as follows:

11. Click the Save button on the toolbar to save the changes.