Sunteți pe pagina 1din 3

The aggregation property

We first examined the aggregation property of unit cost and ensured that it was set to
average. Remember that the unit cost here comes from the sales table. The grain of this table
is sales entries or orders. This means there will be many entries for each product and their
unit cost will repeat.
We want to show only one entry for each product and the unit cost needs to be rolled up
correctly. The aggregation property determines what value is shown for unit cost when
calculated at product level. If it is set to Total, it will wrongly add up the unit costs for
each sales entry. Hence, we are setting it to Average. It can be set to Minimum or
Maximum depending on business requirements.
The rollup aggregation property
In order to show the maximum unit cost for product type, we create an aggregate type of
footer in step 4 and set the Rollup Aggregation to Maximum in step 8.
Here we could have directly selected Maximum from the Summarize dropdown
toolbox. But that creates a new data item called Maximum (Unit Cost).
Instead, we ask Cognos to aggregate the number in the footer and drive the
type by rollup aggregation property. This will reduce one data item in query
subject and native SQL.
Multiple aggregation
We also need to show the overall average at the bottom. For this we have to create a new data
item. Hence, we select unit cost and create an Average type of aggregation in step 5. This
calculates the Average (Unit Cost) and places it on the product line and in the overall footer.
We then deleted the aggregations that are not required in step 7.
There's more...
The rollup aggregation of any item is important only when you create the aggregation of
Aggregate type. When it is set to automatic, Cognos will decide the function based on the
data type, which is not preferred.
It is good practice to always set the aggregation and rollup aggregation to a meaningful
function rather than leaving them as automatic.
Report Authoring Basic Concepts
18

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 type and Sales fact / 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...
In this recipe, we need to create a filter that will be used to select the retailer if the Order
method is Sales Visit. We will check what will happen if we use the if then else
construction inside the filter and how to overcome any problems with the following steps:
1. Here we need to apply the retailer filter only if Order method is Sales Visit.
So, we start by adding a new detail filter.
2. Define the filter as follows:
if ([Order method type]='Sales visit') then ([Sales (query)].
[Retailers].[Retailer name] = ?SalesVisitRetailer?).
3. Validate the report. You will find multiple error messages.
4. Now change the filter definition to:
(([Order method type]='Sales visit') and ([Sales (query)].
[Retailers].[Retailer name] = ?SalesVisitRetailer?)) or ([Order
method type]<>'Sales visit').
5. Validate the report and it should 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.
Chapter 1
19
The workaround for this problem is to use and...or clauses as shown in this recipe. The
if condition and corresponding action item are joined with the and clause. The else part
is taken care of by the 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)].[Retailers].[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.
Formatting data – dates, numbers, and
percentages
Virtually all reports involve displaying numerical information. It is very important to correctly
format the numbers. In this recipe, we will create a report which formats dates, numbers,
and percentages.
Date transformation and formatting are important in business reports. We will see two ways
of displaying MONTH-YEAR from the Shipment Date Key. We will apply some formatting to a
numeric column and will also configure a ratio to be displayed as a percentage.
Getting ready
Create a simple list report with Products / Product line, Products / Product type, and Time
(ship date) / Date (ship date) as columns from the Sales (query) namespace.
Also, add Quantity, Unit price, and Unit cost from the Sales fact Query Subject.
Create a grouping on Product line and Product type.
Report Authoring Basic Concepts
20
How to do it...
In this recipe, we will check how to apply different formats on the data items.
1. We will start by formatting the date column we have (check in Cognos 8).
2. Select the Time (ship date) / Date (ship date) column and open Data Format from
the Properties pane. Open the Data Format dialog box by clicking on the Browse
button next to the Data Format property.
3. Choose the format type Date, set Date Style to Medium, and set Display Days to No,
as shown in the following screenshot:
4. Now select the Quantity column in the report. Choose Data Format from property
and open the dialog box again.
5. This time select Number as the type and set the different properties as required. In
our example recipe, we will set the Number of Decimal Points to 2 and use brackets
() as a Negative Sign Symbol.
6. Finally, we will add the ratio calculation to the report. For that, add a new query
calculation and define it as follows:
[Unit price]/[Unit cost]
Chapter 1
21
7. Select this column and from the Data Format property dialog box, set it as Percent.
Choose % as the Percentage Symbol and set the Number of Decimal Places to 2.
Also, set the Divide by Zero Characters to N/A.
8. Run the report to test it.

S-ar putea să vă placă și