This is part 2 of my little essay about how to get the values that you want show up on the report where you want them.
The first part talked about the tuple() function. If it wasn't clear enough, it will be...
Crosstabs and tuple() are so related it's difficult to explain one without the other.
If you've used pivot tables in Excel then roughly that's what you can expect from a crosstab.
- labels for the numbers we see in the middle of the table
- members of a dimension so that we give some context to those numbers.
Tables are the best way to "flatten" the dimensional data since most of us are not comfortable looking at 5 dimensional Rubik cubes :)
Crosstabs do provide a way for displaying multi ( > 2) dimensional data in a way that we can digest.
I'll provide examples going from the simplest case towards the more difficult.
A crosstab axes contains either a member set or a tuple() expression. (Even when it looks just like a simple measure.) Member sets are "expanded" during runtime - thereby creating multiple rows or columns. tuple() expressions are evaluated for every cell in the row or column.
I will use the same example as in part one:
Sales - measure
Branch, Product, Time - dimensions
1., one dimension - one measure
measure |
----------+-------
dimension1| <1234>
The crosstab will work much like a simple list. When you think you need only a list use this instead. Lists are not meant for dimensional model.
You may notice that the horizontal axes is left empty. That's OK.
The upper left corner of the crosstab ddisplays the default measure. You can drag a measure there or into the "content" area.
Most people get confused by this and think that the crosstab can only display one measure.
It's not true. As you can see later a crosstab can display as many measures as you want.
The default measure is used to evaluate tuple() expressions where the measure is not specified.
I'll show examples of that later. Just keep it in mind.
e.g.
Sales |
------+-------
Branch| <1234>
"Sales" really becomes tuple(Sales)
Sales |
-------------------------+---------
Richmond AutoMall | 450,000
-------------------------+---------
North Vancouver AutoMall | 129,000
-------------------------+---------
Kingsway Nissan | 39,000
-------------------------+---------
The dimension is expanded.
The tuple expression is evaluated in the context of the crosstab like this
tuple(Sales, currentMember(Branch), defaultMember(Time), defaultMember(product))
The defaultMember practically means Product and Time resulting in rolled-up values along these dimensions.
2., two dimensions - one measure
measure | dimension1
-----------+-----------
dimension2 | <1234>
This is the "classical" crosstab.
e.g.
Sales | Time
------+------
Branch| <1234>
Note that "Sales" is still tuple(Sales)
that gets evaluated like
tuple(Sales, currentMember(Branch), currentMember(Time), defaultMember(Product))
Both dimensions will be expanded resulting in something like this:
Sales | 1/1/2008 | ... | 1/31/2008
-------------------------+----------+ ... +----------
Richmond AutoMall | 20,000 17,000
-------------------------+----------+ ... +----------
North Vancouver AutoMall | 23,000 0
-------------------------+----------+ ... +----------
Kingsway Nissan | 18,000 24,500
3., one dimension - many measures
The crosstab can have multiple measures. One of them is the default.
measure1 | measure1 | measure2 ... measure_n
-----------+----------+---------+ ... +---------
dimension1 | <1234> | <1234> | ... | <1234>
In this example measure1 is the default measure.
Having a default measure we can do something like this:
fusion_sales := tuple([Product]->[Ford Fusion])
Sales | Sales | fusion_sales
-------+-------+-------------
Branch | <1234>| <1234>
Note that the tuple() expression only specified the product dimension.
Cognos will figure out from the context that we are talking about Sales; because Sales is the default measure.
fusion_sales will be evaluated like this:
tuple(Sales, currentMember(Branch), defaultMember(Time), [Product]->[Ford Fusion])
It will give the total of Ford Fusion sales per branch.
The arrow ``->'' is Cognos's notation for specifying a member.
Try dragging in a member from a dimension... you'll see.
(It's a powerful tool to create "custom measures" so to speak. So we won't have "ford Fusion Sales" as a separate metric in our cube..)
4., three or more dimensions - one measure
When we need more than 2 dimensions we have to nest them into one another.
measure | dimension3
------------------------+-----------
dimension1 | dimension2 | <1234>
+------------+-----------
| dimension2 | <1234>
-----------+------------+-----------
e.g.
Sales | Time
-----------------+-------
Branch | Product | <1234>
+---------+-------
| Product | <1234>
-------+---------+-------
as the dimensions are expanded all combinations will be created
Sales | 1/1/2008 ...
-----------------------------------------+---------
Richmond Autmoall | Ford Fusion |
+---------------+---------
| Nissan Maxima |
+---------------+---------
| Honda Civic |
-------------------------+---------------+---------
North Vancouver Automall | Ford Fusion | *
+---------------+---------
| Nissan Maxima |
+---------------+---------
| Honda Civic |
* Sales of Ford Fusion at North Vancouver Automall on 1st Jan
Note how the nested dimension (Product) is repeatedly expanded for every member of the outer dimension (Branch).
5., many dimensions - many measures
Using nesting you can go wild!
Measure1 | dimension1 |
+---------------------+
| measure1 | measure2 |
------------------------+----------------------
dimension2 | dimension3 | <1234> | <1234> |
+------------+----------+-----------
| dimension3 | <1234> | <1234> |
+------------+----------+----------+
In the next part I'll show some practical examples and talk about member sets.
Just to wet your apetite... think about not having the entire dimension along the axes, only some specific members you want...