IBM Cognos 10 Report Studio Cookbook(Second Edition)
上QQ阅读APP看书,第一时间看更新

Using conditional blocks – many reports in one

The purpose of this recipe is to introduce you to a very useful and powerful control of Report Studio called conditional blocks.

Users want a report on sales figures. They want the facility to split the numbers by product lines, periods, or retailer region, any one at a time. For convenience purposes, they don't want three different reports, instead they are looking for one report with the facility to choose between the report types.

Getting ready

Create a report with three list objects. Define the list columns as follows:

  • List 1: Products / Product line and Sales fact / Quantity
  • List 2: Time / Year, Time / Month, and Sales fact / Quantity
  • List 3: Retailers / Region and Sales fact / Quantity

Define appropriate grouping, sorting, and aggregation for all the list objects. Make sure that all objects use different queries as shown in the following screenshot:

How to do it...

Conditional blocks are very powerful tool that you can make your report very fixable. In this recipe, we will create three different reports, but using the conditional blocks we will be able to show them in the same report. The procedure to do this is as follows:

  1. We will start by creating a prompt for the report type. Go to Page Explorer and add a prompt page.
  2. Drag a new value prompt object on to the prompt page. Define parameter name as paramReportType. Do not define any filtering, use value, or display value in the prompt wizard.
  3. Select the value prompt and open Static Choices from its properties.
  4. Define three static choices as shown in the following screenshot:
  5. Now go to Condition Explorer and create a new String variable. Define it as ParamValue('paramReportType').
  6. Add three values for this variable as BP, BT, and BR. Change the name of the variable to ReportType.
  7. Now go to the report page. Add a new conditional block from the Toolbox pane.
  8. Select the conditional block and open the Block Variable dialog from the properties. Select the ReportType variable from the dropdown and then click on the OK button as shown in the following screenshot:
  9. Now choose BP as the current block from properties. Select the first list object that shows sales quantity by products. Drag this list into the conditional block. Please note that you need to use the Ancestor button to select the whole list before dragging it in.
  10. Change the current block property of the conditional block to BT. Drag the Sales by Time list into the block.
  11. Repeat the same for BR and the last list object.
  12. On the report page header, select the Double click to edit text item. Change its Source type property to Report expression.
  13. Define the expression as ParamDisplayValue('paramReportType').
  14. Run the report to test it.

How it works...

We saw how to define conditional variables and use them as style variables in the Adding conditional formatting recipe. In this recipe, we are checking how conditional variables can be used with the conditional blocks.

A conditional block is a useful component that allows you to show certain objects in a certain condition. While condition styling and rendering are for finer control, conditional blocks are useful for coarse actions like showing/hiding whole object and switching between objects.

Here, all list objects use different queries. So, each query subject will have only the required columns. Depending on the prompt selection, only one of those queries will be fired and will bring back appropriate columns.

It was possible to have just one list object and one query subject with all columns, and hide/show columns are required. This will be done using conditional styling that you have already learnt. However, the purpose of this recipe is to introduce you to conditional blocks. Now you can be creative and use the conditional blocks in real life scenarios. Please note that we checked for the use value in condition variable (paramValue) whereas we showed the display value (paramDisplayValue) in header. This topic was discussed in Chapter 1, Report Authoring Basic Concepts.

There's more...

It is good practice to define something to be displayed for the Other condition of the conditional variable. Do not keep the block empty for any condition, unless that is the requirement.

Conditional block finds its application in many scenarios. For example, showing certain warnings like No records found or displaying summary or detailed report depending on the user's choice.