Академический Документы
Профессиональный Документы
Культура Документы
Copyright
Your use of this document is subject to the Terms of Use governing the
Cognos software products and related services which you have licensed or
purchased from Cognos. The information contained in this document is
proprietary information of Cognos Incorporated and/or its licensors and is
protected under copyright and other applicable laws. You may use the
information and methodologies described in this document 'as is' or you may
modify them, however Cognos will not be responsible for any deficiencies or
errors that result from modifications which you make. Copyright 2006 (c)
Cognos Incorporated. All Rights Reserved.
You can print selected pages, a section, or the whole book. Cognos grants
you a non-exclusive, non-transferable license to use, copy, and reproduce the
copyright materials, in printed or electronic format, solely for the purpose of
providing internal training on, operating, and maintaining the Cognos
software.
This document is maintained by the Best Practices, Product and Technology
team. You can send comments, suggestions, and additions to Best Practices,
Product and Technologies.
Proprietary Information
Introduction To MDX Functions 3
For Cognos 8 Report Studio
Contents
1 INTRODUCTION ............................................................................................ 4
1.1 PURPOSE .............................................................................................................. 4
1.2 APPLICABILITY ....................................................................................................... 4
1.3 EXCLUSIONS .......................................................................................................... 4
1.4 DOCUMENT CONVENTIONS AND SUPPORTING TECHNOLOGY ................................................ 4
1.5 SUPPORTING MATERIALS ........................................................................................... 4
2 REPORT STUDIO AND OLAP DATA ................................................................ 4
3 OVERVIEW OF OLAP FOR COGNOS 8 ............................................................ 5
3.1 OLAP TERMINOLOGY ............................................................................................... 5
3.2 OVERVIEW OF REPORT STUDIO MDX FUNCTIONS ............................................................ 7
4 FUNDAMENTAL CONCEPTS FOR WORKING WITH OLAP DATA IN COGNOS 8
REPORT STUDIO....................................................................................................... 8
4.1 IMPLICIT SETS, TUPLES, AND MEMBERS IN REPORT STUDIO ............................................... 8
4.2 EXPLICIT SETS, TUPLES, AND MEMBERS IN REPORT STUDIO ............................................... 9
4.2.1 Tuples .............................................................................................................. 10
4.2.2 Members .......................................................................................................... 10
4.2.3 Sets ................................................................................................................. 11
4.2.4 The currentMember and tuples........................................................................... 11
5 NAVIGATING HIERARCHIES WITH MDX FUNCTIONS ................................ 13
5.1 REFERENCING MEMBERS WITH PARENTS, CHILDREN, AND PREVIOUS MEMBERS ...................... 13
5.2 DIMENSION ROLLUP AGGREGATIONS .......................................................................... 15
5.3 LEVERAGING THE DIMENSION STRUCTURE.................................................................... 15
5.4 USING SET FUNCTIONS........................................................................................... 19
5.5 MEMBER UNIQUE NAMES (MUNS) ............................................................................. 20
5.5.1 When is [2006/Dec] not [2006/Dec]?.................................................................. 21
6 SYNTAX FOR USING REPORT STUDIO MDX FUNCTIONS ........................... 23
6.1 PARAMETER TYPES ................................................................................................ 23
6.2 OPTIONAL PARAMETERS .......................................................................................... 24
7 WORKING WITH SETS OF MEMBERS.......................................................... 25
7.1 USING THE MDX UNION() FUNCTION ......................................................................... 25
7.2 USING THE MDX EXCEPT() FUNCTION TO MANIPULATE MEMBER SETS ................................ 28
7.3 USING THE MDX ORDER() FUNCTION TO SORT MEMBER SETS .......................................... 29
8 MEMBER SUMMARY FUNCTIONS ................................................................ 31
8.1 THE MDX TOTAL() AND AGGREGATE() FUNCTIONS ........................................................ 31
8.2 THE MDX PERCENTAGE() FUNCTION .......................................................................... 33
9 CONCLUSION .............................................................................................. 34
APPENDIX A............................................................................................................ 35
MDX FUNCTION CATEGORIES .............................................................................................. 35
MEMBER FUNCTION DESCRIPTIONS ........................................................................................ 35
SET FUNCTION DESCRIPTIONS.............................................................................................. 36
LEVEL AND HIERARCHY FUNCTION DESCRIPTIONS ...................................................................... 38
TUPLE FUNCTION DESCRIPTIONS........................................................................................... 38
OTHER FUNCTION DESCRIPTIONS .......................................................................................... 39
Proprietary Information
Introduction To MDX Functions 4
For Cognos 8 Report Studio
1 Introduction
1.1 Purpose
This document introduces the fundamental concepts behind the OLAP query
language, MDX, and how they apply to creating Report Studio reports. The
content is not a comprehensive review of all the MDX functions and their
interactions.
1.2 Applicability
The techniques described apply to Cognos 8 MR2 Report Studio functionality.
It is assumed that the reader is already familiar with using Report Studio.
1.3 Exclusions
Topics including dimensional modeling, specific cube implementations (i.e.
PowerPlay cubes versus MSFT Analysis Services cubes), or writing complete
MDX functions by hand will not be covered.
Proprietary Information
Introduction To MDX Functions 5
For Cognos 8 Report Studio
Proprietary Information
Introduction To MDX Functions 6
For Cognos 8 Report Studio
Level Dimension
Hierarchy Member
Folder
Level in
Hierarchy
Proprietary Information
Introduction To MDX Functions 7
For Cognos 8 Report Studio
Slicer – A slicer is similar to the SQL “where” clause that limits the data
returned in a query. As an example, a slicer of [2005] will limit any data
returned to 2005. There are some considerations for the report writer when
using a slicer:
Proprietary Information
Introduction To MDX Functions 8
For Cognos 8 Report Studio
OR
{ [Golf Equipment].Children,
[Camping Equipment].Children }
OR
{ [Golf Equipment].Children } +
{[Camping Equipment].Children }
The above example shows that there is often a correlation between a version
of a “standard” MDX syntax and the Cognos 8 syntax. Report Studio also
provides extensions and added capabilities to MDX that simplify complex
calculations and aggregations.
Proprietary Information
Introduction To MDX Functions 9
For Cognos 8 Report Studio
The simplest report that could be written is a list report with just a measure
as a data item. From the [Great Outdoors Company] cube, a list with the
[Revenue] measure dragged in returns:
Figure 1
By dragging in the [Product line] level, the report shows the [Revenue] for
each member of [Product line]. That is, [Product line] represents the set of
members [Camping Equipment] through [Personal Accessories].
Figure 2
Proprietary Information
Introduction To MDX Functions 10
For Cognos 8 Report Studio
The tuple() function will return the value for the combination of every
member included in the function. To illustrate, creating the same list report
as in Figure 1 with [Revenue] and [Product line] using the tuple() function,
the [Revenue] measure would not be dragged onto the list, but instead would
be replaced by a custom [Data Item] calculations with the formula tuple(
[Revenue] ). The use of the tuple() function here is for illustration only. When
using a measure such as [Revenue], the tuple() function is implied and does
not need to be explicitly written.
4.2.2 Members
Dragging the [Product line] level from the [Products] hierarchy into a list or
crosstab will reference a set of data consisting of the members of the
[Product line] level. In this case, Report Studio uses the MDX members()
function to return all [Product line] members when producing the underlying
MDX query for the list. The members() function will return the set of
members in the [Product line] level of the products dimension. The definition
of the members function in Report Studio is:
Proprietary Information
Introduction To MDX Functions 11
For Cognos 8 Report Studio
Instead of dragging in the [Product line] level to the list, a [Data Item] could
be created which contains the function members( [Product line] ) to achieve
the same result as in Figure 1. However, as with the tuple function the
reference to the level itself will implicitly include a reference to the members
function and in most cases the use of members() within an expression is not
necessary. The order of the members in the Insertable objects pane is
defined by the structure of the cube and will be the default order of the
members on a report.
Figure 3
4.2.3 Sets
Similar to the members() function, Report Studio uses the MDX set() function
to create1 a set of members when specific members are dragged onto a
report layout. Using a crosstab (to avoid nesting in a list), [Camping
Equipment] and [Outdoor Protection] could be placed into the rows of a
crosstab and [Revenue] to the measures, giving the result in Figure 4
Figure 4
The MDX set() function could be used in a query data item with the function
set([Camping Equipment], [Outdoor Protection]) instead of dragging
individual members. Sets are the key to driving many reports, including
creating custom aggregations over sets of data, or choosing what data to
display.
4.2.4 The currentMember and tuples
The tuple() function does not have be explicitly referenced in order to identify
the current [Product line] member. This relationship is implied by the nesting
in the list, crosstab, or chart.
1
The set of data returned is actually done using the union() statement, which will be covered later in this
document.
Proprietary Information
Introduction To MDX Functions 12
For Cognos 8 Report Studio
Set of
[Product line]
members
currentMember ( hierarchy )
Returns the current member of the hierarchy during an iteration.
If the specified hierarchy is not present in the context in which
the expression is being evaluated, its default member is assumed.
2
The completeTuple() will use the default member of a hierarchy rather than the
currentMember(). This typically evaluates to the root of a hierarchy unless otherwise defined
within the completTuple arguments. This function is useful when the current context of a
query should be discarded to reference another value explicitly.
3
A more detailed explanation of this is covered later in the document.
Proprietary Information
Introduction To MDX Functions 13
For Cognos 8 Report Studio
Sets
S
e Values
t
s
Figure 6
This is the same as the tuple example in the list report, with the addition of
having to reference members from other dimensions that exist in the
crosstab.
For the most part the use of tuple and currentMember are not necessary for
simple reports because the current context and measure value will be
evaluated based on the structure of the list, crosstab, chart, etc. These
functions will play a more significant role in advanced reporting where the
current context from the query container needs to be overridden to retrieve
values that do not match the current row, column, and slicer intersection.
Proprietary Information
Introduction To MDX Functions 14
For Cognos 8 Report Studio
All Time
Parent of
[Q1 2005] FirstChild FirstSibling
2005 of [2005] 2006 of [Q4 2006]
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
FirstSibling
Jan Feb Mar Apr May Jun of [Q1 2006]
PrevMember of NextMember of
[May 2005] [May 2005]
The parent() of the [Q1 2005] member is [2005]. The parent() of the [Jan
2005] member is [Q1 2005]. The hierarchy navigation functions follow the
family tree paradigm of children, parents, siblings, etc.. For example, the
function firstSibling() returns the member within the branch under the parent
of the hierarchy that it is a part of. In the above diagram, the
firstChild([2006]) is [Q1 2006]. The firstSibling([Q1 2006]) is [Q1 2006], not
[Q4 2005] because it stays within the context of its parent, [2006]. This
behavior keeps from having to code around situations such as “if at the
firstSibling() of the Quarter level, then return Q1, else…”.
Conversely, functions that do not follow the family tree naming convention do
not restrict themselves to staying within the dimension tree hierarchy
structure. The members() function returns all the members of a level,
regardless of the parent member. The function
members([GOC].[Time].[Quarters]) returns all the members in the quarter
level ([Q1 2005] through [Q4 2006]) Similarly, the prevMember() and
nextMember() functions do not restrict themselves to the parent of the
current member it is under. The prevMember() of [Q1 2006] is [Q4 2005].
The prevMember() of [Jan 2005] in Figure 7 would be null.
Proprietary Information
Introduction To MDX Functions 15
For Cognos 8 Report Studio
Figure 8
The calculation would be to take the total [Revenue] for each [Product line]
member, and then divided it by the total [Revenue] for all [Product line]
members.
Proprietary Information
Introduction To MDX Functions 16
For Cognos 8 Report Studio
All the values in the cube are determined by the intersection of the
dimensions referenced in a function and the rollup aggregation function. The
rollup of values is SUM for the [Revenue] values in the [Products] dimension.
Therefore, the parent of current member of [Product line] level will be the
[Products] level in the hierarchy, which gives the total [Revenue] for all
[Product line](s).
Figure 9
Proprietary Information
Introduction To MDX Functions 17
For Cognos 8 Report Studio
Figure 10
A Report Studio user may think that if the report is calculating the percentage
for a product line by dividing by the total for all products, why use the
parent( ) function? Why not explicitly reference the [Products] member? The
products member has all the [Product line] members as its’ children, so it
represents all the [Product line] members. It would seem simpler to just drag
the [Products] member into the function to replace the parent(
currentMember([GOC].[Products].[Products]) ):
tuple( currentMember(
[great_outdoors_company].[Products].[Products] ) , [Revenue] ) /
tuple( [Products] , [Revenue] )
Figure 11
Running the report shows that the numbers are equivalent between the two
formulas…
Figure 12
Proprietary Information
Introduction To MDX Functions 18
For Cognos 8 Report Studio
Or at least the numbers will be the same until the user drills down on a
product member (i.e. [Camping Equipment]):
Figure 13
tuple( currentMember(
[great_outdoors_company].[Products].[Products] ) ,[Revenue] )
/
tuple( parent(currentMember(
[great_outdoors_company].[Products].[Products] ) ) , [Revenue] )
has a denominator that is the parent of the current member in the list. This is
[Products] when at the [Product line] level of [Camping Equipment].
However, when the current member is at the [Product type] level, such as
with [Cooking Gear], then the parent will be in the [Product line] level; in this
case [Camping Equipment].
tuple( currentMember(
[great_outdoors_company].[Products].[Products] ) ,[Revenue] )
/
tuple( [Products] , [Revenue] )
explicitly references the [Revenue] measure value for the [Products] level.
This is regardless of which product member is being evaluated in the current
context of the list.
The results are that no matter where a user drills, the first formula calculates
the percentage [Revenue] for a product member of the next level up in the
hierarchy (the parent). The second formula always calculates the percentage
of the total [Products] revenue.
Proprietary Information
Introduction To MDX Functions 19
For Cognos 8 Report Studio
2005 2006
Q1 Q2 Q3 Q4 Q1 Q2 Q3 Q4
Children of
Jan Feb Mar Oct Nov Dec [2006]
Members( [Months] )
Head(members([Months], 2)
Figure 14
Proprietary Information
Introduction To MDX Functions 20
For Cognos 8 Report Studio
Children ( [2006] )
Members( [Months] )
Head(members([Months], 2)
Tail(members([Quarters], 2)
Figure 15
All cube technologies use some form of MUNs to identify members. Using the
Great Outdoors Company [Years] dimension from the Cognos 8 sample data,
a Report Studio user can right mouse on any member in a dimension, choose
view properties, and see the MUN for that member. Using the [2006/Dec]
member from the [Years] hierarchy, the MUN is defined as:
4
This is a generalization; of course custom calculations can be created and used in a report.
Proprietary Information
Introduction To MDX Functions 21
For Cognos 8 Report Studio
[GOC].[Years].[Years].[Month]->:[PC].[@MEMBER].[20061201-
20061231]5
MUN’s can change if the cube is re-organized (old roads demolished, new
one’s built). Report writers need to be cognizant of this if they use specific
MUN references. Fortunately, many cube structures are relatively static due
to selection of appropriate keys during cube creation, and members are also
often referenced indirectly through formulas or queries instead of through
explicit use of MUN’s.
5.5.1 When is [2006/Dec] not [2006/Dec]?
The underlying structure of MUNs does have an impact on Report Studio
report design. Different hierarchies in a dimension can reference the same
member, but have different MUNs. A common example can be seen with
Cognos PowerPlay cubes where the time dimension includes hierarchies for
[Years] and [Current Month]. The MUN values in Figure 16 show that the the
MUN for [2006/Dec] under the [Current Month] hierarchy is not the same as
the MUN for [2006/Dec] under the [Years] hierarchy. Both hierarchies can be
used to get the [2006/Dec] member, but they take different paths, and
therefore have different MUNs. The hierarchies are not interrelated. This
same concept also applies to other cube technologies.
Figure 16
The implication of this internal cube MUN structure to the report writer can be
best shown by an example. One common request is to use the [Current
Month] member as an anchor date for a report.
5
The syntax of MUN references can change from release to release. Older MUN syntax will continue to
be supported in later releases, although new MUNs will be generated with the syntax for the current
version.
Proprietary Information
Introduction To MDX Functions 22
For Cognos 8 Report Studio
Figure 17
If the [Current Month] is [2006/Dec], then the current quarter logically would
be [2004 Q4]. The report writer drags the [Current Month] member from the
[Current Month] level in the [Current Month] hierarchy onto a crosstab. To
get the current quarter, the report writer drags the [Quarter] level from the
[Years] hierarchy and nests it above the [Current Month]. If the [Current
Month] member is [2006/Dec], the expectation is that the [Quarter] will be
[2006 Q4]. The following error occurs when the report is run.
Figure 18
Why this “error” is thrown can be seen by examining the MUNs and the
hierarchies in Figure 16. The [2006/Dec] member as referenced in the
[Current Month] hierarchy does not have a path or relationship to the [2006
Q4] member in the [Years] hierarchy. There is no [Quarter] level above the
[Current Month] member or level in the [Current Month] hierarchy. This is not
an error, but a consequence of how cubes work. The same results will be
encountered regardless of the underlying OLAP technology being used.
Fortunately there are several options for the Report Studio developer using
MDX functions to mitigate this issue if it arises. One solution, the
closingPeriod() function will be covered in the next section.
NOTE: One of the key strengths of Report Studio is that a developer can
place unrelated dimensions/hierarchies on the same edge. The following
report specification will run even though [Current Month] and [Quarter] are
from different hierarchies:
Figure 19
Proprietary Information
Introduction To MDX Functions 23
For Cognos 8 Report Studio
The most common occurrence of this coercion error is when using the
currentMember() function. A typical case is when a developer drags the
[Products] level into a crosstab or list, and wants to use the currentMember()
function in custom calculation. It is logical to think: “I’m at the [Products]
level; therefore I need the currentMember() of [Products] level.” Running
report will then give the coercion error. The reason is that the
currentMember() function requires a hierarchy as a parameter. This makes
sense since the current member can be any member in any level in a
dimension. The level within a hierarchy for the currentMember() will change
when a user drills up or down within the hierarchy.
Proprietary Information
Introduction To MDX Functions 24
For Cognos 8 Report Studio
Proprietary Information
Introduction To MDX Functions 25
For Cognos 8 Report Studio
Figure 22
The report in Figure 22 can use the topCount() function while taking
advantage of Report Studio nesting. In the example above, the [Product line]
level is dragged into the rows of a crosstab, followed by a nested data item
with the topCount() function6. The syntax of the topCount() function is as
follows:
6
Remember that dragging a level into a crosstab or list in Report Studio is shorthand for the MDX
function members( [dragged level] ).
Proprietary Information
Introduction To MDX Functions 26
For Cognos 8 Report Studio
If the report was run at this point, the nested topCount() function would
return only the top two [Product type] members nested after the [Product
line] members. For [Camping Equipment], the nested members returned by
topCount() would be [Lanterns] and [Cooking Gear]7.
The next step is to get the [Product line] member into the report. As shown
in Figure 22, the requirement is to include the [Quantity sold] for [Camping
Equipment] before [Lanterns] and [Cooking Gear], and on for each [Product
line] member. The MDX union() function can be used to combine the two
sets8:
Because [Product line] is nested before the data item with the topCount()
function in this example, the union() function can be used to combine the
current [Products] hierarchy member with the topCount() set of members as
follows:
This will give the results of having [Camping Equipment], and all other the
[Product line] members shown before the top two [Product type] members
by [Quantity sold] for each [Product line] member as shown in Figure 22.
Report Studio’s nesting capabilities often help keep the number MDX
functions needed to a minimum. The same result as shown in Figure 22 for
the topCount() example could be obtained by using the following MDX
formula using the children() function on the current member of [Product line]
in the crosstab:
7
The proof is left up to the interested reader.
8
sets can consist of multiple, one, or no members (empty set).
Proprietary Information
Introduction To MDX Functions 27
For Cognos 8 Report Studio
To illustrate the drag and drop capabilities, the [Product line] data item could
have also been nested next to the topCount data item to produce the same
results union query and the same results. The layout after the drag and drop
operation would look like the following:
Figure 23
On a more advanced note the results could have also been obtained without
nesting by using the nestedset() function to define the nesting rules within
the expression rather than by using the layout:
nestedSet([great_outdoors_company].[Products].[Products].[Product
line],
union(currentMember([great_outdoors_company].[Products].[Produc
ts]),
topCount(children(currentMember([great_outdoors_company].[Pr
oducts].[Products])),2,[Quantity sold])))
Figure 24
The specific details of the nestedSet() are not covered in this document.
Proprietary Information
Introduction To MDX Functions 28
For Cognos 8 Report Studio
The syntax of the except() function from the Report Studio function tip is:
The except() function to return all [Product type] members except the top
two by [Quantity sold] would be:
The first parameter to the except() function is the set of all [Product type]
members. The second, is the set of members that are the top two by
[Quantity sold], just as in the previous union() example. The result set from
the topCount() function are the members that are to be excluded from the
result set.
To complete the example where the report is required to have the [Product
line] member total before the [Product type] member set, the except()
statement can be used as a parameter to a union() statement.
Proprietary Information
Introduction To MDX Functions 29
For Cognos 8 Report Studio
The [Product line] level can be used in the union statement because it takes
advantage of Report Studio nesting giving the result shown in Figure 25.
Figure 25
Using order() to sort the members is done by placing the order function in
the correct position in the query, shown in bold below:
By placing the order() function within the union and around the member set
returned by the except() function, the report will always show the current
[Product line] first as seen in Figure 26.
Proprietary Information
Introduction To MDX Functions 30
For Cognos 8 Report Studio
Figure 26
The value that the order() function sorts on is simply [Quantity sold] in this
example. If [Quantity sold] were nested under another dimension, such as
[Years], then a tuple() function would be needed to explicitly reference the
sort value defined by a specific combination of the [Product type] and [Years]
members.
There are two types of sorting that can be done by the order function:
1. Within the dimension hierarchy
2. “breaking” the hierarchy.
By default, the order() function will sort members within their respective
hierarchies. “Breaking” the hierarchy means that the order() function ignores
the hierarchical structure of the dimension. The list report in Figure 27 orders
the members of the product dimension using the DESC (non-breaking
dimension ordering) and BDESC (break dimension ordering) parameters.
Figure 27
Proprietary Information
Introduction To MDX Functions 31
For Cognos 8 Report Studio
The ordering of the two lists in Figure 27 is accomplished with the following
functions:
The DESC descending order parameter used in the list on the left in Figure 27
tells the order() function to sort each member within the context of its
hierarchy. Based on the hierarchy, [Products] is the first member returned by
order(), then [Camping Equipment] ([Product line] level). The next set of
members will then be the children of [Camping Equipment] ([Product type]
level), followed by the children of the [Product type] ([Product name] level).
Once all of the members of [Camping Equipment] down to its lowest level
has been sorted, the next [Product line] member in the sort, [Cooking Gear]
and all its’ descendants are sorted. [Camping Equipment] returns before
[Cooking Gear] since [Camping Equipment] has a greater [Quantity sold]
value. The order() follows the structure of the dimension hierarchy with
ordering occurring within each hierarchy level.
The BDEC parameter used in the order() function in the list on the left, tells
the order() function to ignore the hierarchy structure and sort on [Quantity
sold] values only. This “breaks” the hierarchy ordering defined in the
dimension, hence the “B” in the BASC and BDESC optional parameter names.
Proprietary Information
Introduction To MDX Functions 32
For Cognos 8 Report Studio
Each function has two signatures, with the first definition for each applying to
MDX usage. total() will total either the “currentMeasure”9 or a value defined
by “expr”. The same applies for the aggregate() function. The two functions
are often interchangeable because the rollup aggregation function defined
within the cube is typically sum, and the totals for a report are done in the
context of a dimension’s hierarchies. How dimension hierarchies can affect
the results of aggregate() and total() can be illustrated by modifying the list
example in Figure 27:
Figure 28
The total() and aggregate() functions used for the calculations in Figure 28:
Notice that the set parameter is the ordered set of product members from the
previous example10.
The total() function returns the total for all members in the [order_BDESC]
set ( [Products] + [Camping Equipment] + [Outdoor Protection] … =
8,861,416 ), which is greater than the total [Products] sold. The number
using total() includes lower level values which have already been rolled up
into the higher level members.
The aggregate() function uses the defined aggregation for the [Products]
hierarchy, which gives the correct amount for the total [Products] sold,
2,215,354. The aggregate() function in this case is equivalent to:
9
currentMeasure refers to the current measure being evaluated in a crosstab.
10
No particular reason for this outside of illustrating that sets can be used for more than just crosstab
edges.
Proprietary Information
Introduction To MDX Functions 33
For Cognos 8 Report Studio
The percentage calculation for the [Quantity sold] of all [Products] in the list
shown in Figure 29 could be:
The percentage of [Quantity sold] is for the [Product] member, that is, the
total [Quantity sold] for all [Products]. This will give the percentage of each
[Products] member [Quantity sold] of the total [Quantity sold]. The formula
to calculate the percentage of the [Quantity sold] of a member’s parent is:
Here the currentMember() and parent() functions are used to find the
member one level higher in the [Products] hierarchy.
The resulting modified list report using the order_DESC is shown in Figure 29.
Figure 29
The first percentage column gives the overall percentage for each [Products]
member. The percentage calculation in the second column using the parent()
calculates the percentage [Quantity sold] for the current member’s parent -
[Lanterns] is 40% [Camping Equipment], [Firefly 2] is 14% of [Lanterns], etc.
For the second percentage the value for [Product] is blank because [Product]
is at the top of the hierarchy and no parent member exists.
Proprietary Information
Introduction To MDX Functions 34
For Cognos 8 Report Studio
9 Conclusion
Report Studio is a very powerful report writing tool that exposes powerful
MDX functions to extend and enhance the types of reports that can be built
from OLAP cube or Dimensionally Modeled Relational data sources. This
document outlines the three key concepts a Report Studio report writer needs
to be comfortable with to be effective with MDX:
11
topCount() and bottomCount(), or topPercent() bottomPercent() are examples of this.
Proprietary Information
Introduction To MDX Functions 35
For Cognos 8 Report Studio
Appendix A
Appendix A categorizes the Cognos 8 MDX functions on whether they work
with members, sets, dimensions, or provide other functionality, such as
information about a member or set. The descriptions are directly from the
Cogno8 MR2 Report Studio tool tips. Categorizing the functions provides a
quick reference for the report designer to determine what functions apply
when building calculations that have members, sets, or need other
information.
Proprietary Information
Introduction To MDX Functions 36
For Cognos 8 Report Studio
Function Description
The result is not guaranteed to be consistent when there is more than one
such ancestor.
closingPeriod Returns the last sibling among the descendants of a member at a specified
level. Typically used with a time dimension.
cousin Returns the child member of member2 with the same relative position as the
member1 is under its parent.
currentMember Returns the current member of the hierarchy during an iteration. If the
specified hierarchy is not present in the context in which the expression is
being evaluated, its default member is assumed.
defaultMember Returns the default member of a hierarchy.
firstChild Returns the first child of a specified member.
firstSibling Returns the first child of the parent of a member.
item Returns a member from a specified location within a set. The index into the
set is zero based
lag Returns the sibling member that is a specified number of positions prior to a
specified member.
lastChild Returns the last child of a specified member.
lastSibling Returns the last child of the parent of a member.
lead Returns the sibling member that is a specified number of positions following
a specified member.
member Defines a member based on the specified expression in the specified
hierarchy. "string1" is used to identify the member created by this function it
must be unique in the query, and must be different from any other member
in the same hierarchy. "string2" is used as the caption of the member; if it is
absent, the caption is empty. If the hierarchy is omitted, the measure
dimension is assumed.
Note: All calculations used as grouping items whose sibling items are other
calculations or member sets, should be explicitly assigned to a hierarchy
using this function, otherwise the results are not predictable. The only
exception to this is where the calculation involves only members of the same
hierarchy as the siblings. In that case the calculation is assumed to belong to
that hierarchy.
nextMember Returns the next member in the level to which the specified member exists.
openingPeriod Returns the first sibling member among the descendants of a member at a
specified level. Typically used with a time dimension.
parallelPeriod Returns a member from a different period in the same relative position as a
specified member. This function is similar to the "Cousin" function, but is
more closely related to time series. It takes the ancestor of "member" at
"level" (call it "ancestor"); then it takes the sibling of "ancestor" that is offset
(follows) by "int exp" positions, and returns the descendants of that sibling
in the same relative position as the specified member as under "ancestor"..
parent Returns the member that is the parent of the specified member.
prevMember Returns the member that immediately precedes the specified member in the
same level.
Proprietary Information
Introduction To MDX Functions 37
For Cognos 8 Report Studio
Function Description
ancestors Returns all the ancestors of a member at a specified level, or distance
above the member. (Most data sources support only one ancestor at a
specified level, but some support more than one. Hence the result is a
member set.)
bottomCount This function sorts a set according to the value of "numeric_exp" evaluated
at each of the members of "set_exp", and returns the bottom "index_exp"
members..
bottomPercent This function is similar to bottomSum, but the threshold is "numeric_exp1"
percent of the total.
bottomSum This function sorts on "numeric_exp2", evaluated at the corresponding
member of "set_exp", and picks up the bottommost elements whose
cumulative total is at least numeric_exp1.
children Returns the set of children of a specified member..
descendants Returns the set of descendants of a set of members at a specified
level(qualified name) or distance(integer 0..n) from the root. Duplicates will
be removed from the set.
Proprietary Information
Introduction To MDX Functions 38
For Cognos 8 Report Studio
Function Description
order Arranges members of a specified set, as determined from the set of values
created by evaluating "value_exp" for each value of the set, and modified
by the third parameter. There are two varieties of order: hierarchized (ASC
or DESC) and non-hierarchized (BASC or BDESC, where B stands for "break
hierarchy"). The hierarchized ordering first arranges members according to
their position in the hierarchy. Then it orders the children of each member
according to "value_exp". The non-hierarchized ordering arranges
members in the set without regard to the hierarchy. In the absence of an
explicit specification, ASC is the default.
rootMembers Returns the root members of a hierarchy
set Returns the list of members defined in the expression. The members must
belong to the same hierarchy.
periodsToDate Returns a set of sibling members from the same level as a given member,
as constrained by a specified level. It locates the ancestor of "member" at
"level", and returns that ancestor's descendants at the same level as
"member", up to and including "member". Typically used with a time
dimension.
siblings Returns the children of the parent of the specified member.
subset Returns a subset of members from a specified set starting "index_exp1"
from the beginning. If the count "index_exp2" is specified, that many
members (if available) are returned. Otherwise, all remaining members are
returned.
tail Returns the last "index_exp" elements of "set exp". The default for
"index_exp" is 1.
topCount This function sorts a set according to the values of "numeric_exp"
evaluated at each of the members of "set_exp", and returns the top
"index_exp" members.
topPercent This function is similar to topSum, but the threshold is "numeric_exp1"
percent of the total.
topSum This function sorts on "numeric_exp2", evaluated at the corresponding
members of "set_exp", and picks up the topmost elements whose
cumulative total is at least "numeric_exp1".
union This function returns the union of 2 sets "set_exp1" and "set_exp2". The
result retains duplicates only when the optional keyword ALL is supplied as
the third argument.
unique Removes all duplicates from the specified set. The remaining members
retain their original order.
Proprietary Information
Introduction To MDX Functions 39
For Cognos 8 Report Studio
Proprietary Information