官术网_书友最值得收藏!

Creating nested report: Defining master detail relationship

Users want to see product lines, products, and corresponding unit costs. For every product, they also want to see the trend of sales over last year.

We need to produce a list report with required information and nest a line chart within it to show the sales trend.

Getting ready

Create a simple list report based on the Sales (query) namespace. Pull Product | Product line, Product | Product name and Sales fact | Unit cost in the list.

How to do it...

  1. We already have a list report that shows the product lines, products, and corresponding unit costs. Please make sure that appropriate sorting and aggregations are applied to the columns.
  2. Now we will add a nested Chart object to show the sales trend for each product.
  3. Drag a new Chartobject from the Insertable Objects pane onto the report as a column.
    How to do it...
  4. Choose an appropriate chart type. In this recipe, we will choose "Line with Markers".
  5. From Source pane, drag Quantity from Sales fact onto the chart as the Default measure. Drag Month key from time dimension under Category and Product name from product dimension as the Series.
    How to do it...

    Tip

    Please note that we are using the month key here in order to show the monthly figures in correct order. You can later on use a category label to show month names. Directly pulling the month name results in alphabetic sorting, and hence in an incorrect trend.

  6. Now click anywhere on the chart and choose Data | Master Detail Relationship from the menu bar.
  7. Create a new link and connect Product name items from both the queries.
    How to do it...
  8. Click the OK button to come back on the Report Page. Now select the Y1 Axis of chart by clicking on it.
  9. Change its Use Same Range for All Instances property to No.
    How to do it...
  10. Now click on the Chart and click the Filter How to do it... button from toolbar.
  11. Define a detailed filter on Current Year from time dimension as required. In this recipe, I will hard code it to 2004. So, the filter is defined as: [Sales (query)].[Time dimension].[Current year]=2004.

    Though in practical cases, you would have to filter for year, rather than hard-coding.

  12. Run the report to test it.
  13. Update the chart properties (size, marker, color, and so on) for better presentation.
    How to do it...

How it works...

Cognos Report Studio allows one report object to be nested within another list report. In the previous recipe of creating sections, we saw that the Report Studio automatically creates nesting for us. In this recipe, we manually created nesting for finer controls.

Master Detail relationship

We need to define this relationship in the following cases:

  1. When outer and inner report objects use different queries.
  2. For any nesting other than 'List within List'.

In order to generate the report, Cognos first fires the Master query on the database to retrieve the records. Then for each record, it fires the Detail query with the filtering as defined in Master-Detail relationship.

Hence, the Detail query is executed multiple times, each time with different filtering.

As it has to retrieve very small amount of information at a time, a page of output is returned very quickly. This is particularly useful when the report is accessed interactively.

There's more...

By using separate queries for the outer and inner report object in nesting, we can have more control on what information is retrieved. In this example, we want to show a sales trend (chart) only for one year—we hard coded it to 2004. Hence, the chart query needs to be filtered on year.

However, the outer query (list of product lines and products) does not need this filtering.

As you can see in the report output, there are some rows with no corresponding graph. For example, Personal Accessories | Auto Pilot. This means there was no selling of this product in the year 2004. If we had used the same query for the list and the chart, this row would have been filtered out resulting in loss of information (Product name and Unit cost) to the users.

See also

With version 8.4 of Cognos Report Studio, a new feature called 'Microchart' is introduced. This type of chart is particularly useful for such in-line spark chart kind of representation.

This version also allows you to quickly insert a chart within a crosstab by right-clicking on row titles (not one-click action for a list report though).

I would highly recommend exploring and experimenting around these features.

主站蜘蛛池模板: 雷山县| 通道| 金寨县| 太原市| 南汇区| 云龙县| 乌鲁木齐县| 汝南县| 金秀| 垦利县| 夏邑县| 仪征市| 中西区| 宁陕县| 丹巴县| 梁山县| 银川市| 类乌齐县| 榆中县| 静安区| 湘阴县| 江达县| 突泉县| 延津县| 和平区| 新野县| 六安市| 九江县| 武隆县| 南郑县| 寿阳县| 吕梁市| 塔城市| 沂南县| 海阳市| 大城县| 耒阳市| 肇源县| 武夷山市| 明光市| 水富县|