- IBM Cognos 8 Report Studio Cookbook
- Abhishek Sanghani
- 688字
- 2021-08-06 17:15:48
Conditional block: 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 block.
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: Product | Product lines and Sales fact | Quantity.
- List 2: Time dimension | Current year, Time dimension | Current month and Sales fact | Quantity.
- List 3: Retailer site | Region and Sales fact | Quantity.
Define appropriate grouping, sorting, and aggregation for all the list objects. Make sure that all objects use different queries.

How to do it...
- We will start by creating a prompt for report type. Go to Page Explorer and add a prompt page.
- Drag a new value prompt object on the prompt page. Define parameter name as paramReportType. Do not define any filtering, use value, or display value in the prompt wizard.
- Select the value prompt and open Static Choices from its properties.
- Define three static choices as shown in the following screenshot:
- Now go to Condition Explorer and create a new String Variable. Define it as:
ParamValue('paramReportType')
. - Add three values for this variable as: BD, BP, and BR. Change the name of the variable to
ReportType
. - Now go to the report page. Add a new Conditional block from the 'Insertable Objects' pane.
- Select the conditional block and open the Block Variable dialog from the properties. Select
ReportType
variable from the dropdown and then click the OK button. - 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 in).
- Change the current block property of the conditional block to BD. Drag the 'Sales by Periods' list into the block.
- Repeat the same for BR and the last list object.
- On the Report Page header, select the Double click to edit text item. Change its Source type property to Report expression.
- Define the expression as
ParamDisplayValue('paramReportType')
. - Run the report to test it.
How it works...
We saw how to define conditional variables and use them as style variables in the '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 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. One such example can be, showing a 'No data' message when query returns no rows.
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.
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.
- 中文版Illustrator CC實用教程
- Solid Works 2021產品設計標準教程
- SolidWorks 2021中文版機械設計從入門到精通
- RESTful PHP Web Services
- PowerPoint 2016實戰從入門到精通(超值版)
- Premiere pro CC中文版自學視頻教程
- 人人都能玩賺AI繪畫
- Instant Flask Web Development
- Photoshop數字圖像處理
- Vulkan實戰
- Cinema 4D/After Effects印象 影視包裝技法精解基礎篇
- Cinema 4D R20完全學習手冊
- Flash ActionScript 3.0互動設計項目教程
- Illustrator CS6平面設計案例教程(微課版)
- Python Text Processing with NLTK 2.0 Cookbook