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

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.

Getting ready

How to do it...

  1. We will start by creating a prompt for report type. Go to Page Explorer and add a prompt page.
  2. 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.
  3. Select the value prompt and open Static Choices from its properties.
  4. Define three static choices as shown in the following screenshot:
    How to do it...
  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: BD, BP, and BR. Change the name of the variable to ReportType.
  7. Now go to the report page. Add a new Conditional block from the 'Insertable Objects' pane.
  8. 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.
    How to do it...
  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 in).
  10. Change the current block property of the conditional block to BD. Drag the 'Sales by Periods' 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 '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.

主站蜘蛛池模板: 乌鲁木齐县| 正安县| 雅江县| 海门市| 湖口县| 克拉玛依市| 渑池县| 阿拉善左旗| 灵石县| 陆良县| 延寿县| 元朗区| 恩平市| 屯昌县| 句容市| 岳池县| 新巴尔虎左旗| 玉龙| 昌邑市| 铜鼓县| 岳普湖县| 宣威市| 新民市| 共和县| 大埔县| 清苑县| 江达县| 修武县| 朝阳区| 库尔勒市| 扶沟县| 丹寨县| 冀州市| 武陟县| 普定县| 青龙| 庄河市| 武强县| 民勤县| 蒲城县| 丹寨县|