- IBM Cognos 8 Report Studio Cookbook
- Abhishek Sanghani
- 356字
- 2021-08-06 17:15:44
Implementing IF THEN ELSE in filters
Business owners want to see the sales quantity by order methods. However, for the 'Sales Visit' type of order method, they want a facility to select the retailer.
Therefore, the report should show quantity by order methods. For the order methods other than 'Sales Visit', the report should consider all the retailers. For 'Sales Visit' orders, it should filter on the selected retailer.
Getting ready
Create a simple list report with Order Method | Order Method and Sales Fact | Sales Quantity as columns. Group by order method to get one row per method and set the aggregation for quantity to TOTAL.
How to do it...
- Here we need to apply the retailer filter only if Order Method is 'Sales Visit'. So, we start with adding a new detail filter.
- Define the filter as:
if ([Order method]='Sales visit') then ([Sales (query)].[Retailer site].[Retailer name] = ?SalesVisitRetailer?)
- Validate the report. You will find multiple error messages.
- Now change filter definition to this:
(([Order method]='Sales visit') and ([Sales (query)].[Retailer site].[Retailer name] = ?SalesVisitRetailer?)) or ([Order method]<>'Sales visit')
- Validate the report and it will be successful.
- Run the report and test the data.
How it works...
The IF
ELSE
construct works fine when it is used in data expression. However, when we use it in a filter, Cognos often doesn't like it. It is strange because the filter is parsed and validated fine in the expression window and IF
ELSE
is a valid construct.
The workaround for this problem is to use the pair of AND..OR
as shown in this recipe. The IF
condition and corresponding action item are joined with AND
clause. The ELSE
part is taken care by OR
operations with the reverse condition (in our example, Order Method <> 'Sales Visit'
).
There's more...
You need not use both AND
and OR
clauses all the time. The filtering in this example can also be achieved by this expression:
([Sales (query)].[Retailer site].[Retailer name] = ?SalesVisitRetailer?)
or
([Order method]<>'Sales visit')
Depending on the requirement, you need to use only OR
, only AND
, or the combination of AND..OR
.
Make sure that you cover all the possibilities.
- iPad+Procreate數字插畫設計案例教程(全彩微課版)
- WordPress 2.7 Cookbook
- Ext JS 3.0 Cookbook
- Spring Python 1.1
- Adobe Photoshop 網頁設計與制作標準實訓教程(CS5修訂版)
- 零基礎玩轉AI繪畫
- VSTO 3.0 for Office 2007 Programming
- 中文版Premiere Pro CC實用教程
- Python Text Processing with NLTK 2.0 Cookbook: LITE
- 24小時學會PowerPoint 2010
- SolidWorks 2018有限元:運動仿真與流場分析自學手冊
- Django 1.0 Template Development
- Visio圖形設計從新手到高手(兼容版)
- Linux Shell Scripting Cookbook
- 詳解AutoCAD 2022室內設計(第6版)