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

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...

  1. Here we need to apply the retailer filter only if Order Method is 'Sales Visit'. So, we start with adding a new detail filter.
  2. Define the filter as: if ([Order method]='Sales visit') then ([Sales (query)].[Retailer site].[Retailer name] = ?SalesVisitRetailer?)
  3. Validate the report. You will find multiple error messages.
  4. Now change filter definition to this: (([Order method]='Sales visit') and ([Sales (query)].[Retailer site].[Retailer name] = ?SalesVisitRetailer?)) or ([Order method]<>'Sales visit')
  5. Validate the report and it will be successful.
  6. 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.

主站蜘蛛池模板: 彭阳县| 平顺县| 资阳市| 叶城县| 南汇区| 韶山市| 金昌市| 全椒县| 郁南县| 绵竹市| 越西县| 乌什县| 东阳市| 桐庐县| 芦山县| 恩平市| 轮台县| 县级市| 平利县| 石门县| 永春县| 汾西县| 巴塘县| 丰城市| 元朗区| 神农架林区| 穆棱市| 当涂县| 台前县| 金乡县| 全州县| 新宁县| 南川市| 栾川县| 淮滨县| 夏邑县| 湖口县| 临邑县| 宁晋县| 赣榆县| 东城区|