MDX Complex Queries
MDX Complex Queries
APRIL
2004
[ ]
DX (Multidimensional Expressions) is a new data extraction mechanism introduced in Hyperion Essbase Analytic
Services release 7.0 (herein referred to as Essbase), that
provides a method for forming complex and robust multidimensional queries.
MDX QUERY
REPORT SCRIPT
REPORT WRITER
INTERFACE
FORMATTED REPORT
OUTPUT IN TEXT
HYPERION
ESSBASE
SERVER
MDX INTERFACE
CLIENT
APPLICATION
MDX QUERY
RESULT IN
BINARY
MDX
RELATED
API'S
(e.g. END-USER
QUERY AND
REPORTING
TOOL)
[ ]
Report writer commands enable a report to be
defined in terms of columns and rows across
one or more pages. The equivalent construct in
MDX is the axis columns, rows and pages are
considered three of the possible axes. A query
may have only one or two axes as well as three
or more (the maximum number that can be
used within a single query is 64). An optional
slicer axis defines a point of view for the query.
[ ]
MDX, like report writer, supports both metadata and data-based sorting. An example of
metadata-based sorting is sorting by member
name or generation number. MDX functions
like Filter, TopCount, and others provide
functionality similar to report writer data range
commands to restrict the range of selected
data.
Whereas report writer allows custom calculations to be performed on the result set of a
query, MDX allows custom calculations to be
defined within the scope of a query itself and
produces the result in the output. This is
accomplished through calculated members. A
calculated member is a member with a specific
custom formula defined for the duration of a
query and is similar to a dynamic-calc member
defined in an Essbase outline. A calculated
member can use a rich set of computation and
referencing primitives.
WITH
MEMBER Scenario.[Qtr to Qtr Variance] AS
'IIF (Is (Year.CurrentMember, Qtr1),
0,
Year.CurrentMember - Year.CurrentMember.PrevMember
)'
SELECT
{ Scenario.Children, [Qtr to Qtr Variance] } on Columns,
Year.Children on Rows
WHERE (East, [100], Sales)
[ ]
East
100
Sales
Actual
Budget
Variance
Variance %
Qtr1
6292
5870
422
7.1891
Qtr2
7230
6760
470
6.95266
938
Qtr3
7770
7300
470
6.43836
540
Qtr4
6448
5570
878
15.763
-1322
WITH
MEMBER [Scenario].[Qtr to Qtr Variance] as
'IIF (IsValid (Year.CurrentMember.PrevMember),
Year.CurrentMember - Year.CurrentMember.PrevMember,
0
)'
SELECT
{ Scenario.Children, [Qtr to Qtr Variance] } on Columns,
Year.Members on Rows
FROM Sample.Basic
WHERE (East, [100], Sales)
East
100
Sales
Actual
Budget
Variance
Variance %
Year
27740
25500
2240
8.78431
Qtr1
6292
5870
422
7.1891
Jan
2105
1960
145
7.39796
Feb
2061
1920
141
7.34375
-44
Mar
2126
1990
136
6.83417
65
Qtr2
7230
6760
470
6.95266
938
Apr
2258
2110
148
7.01422
132
May
2347
2190
157
7.16895
89
Jun
2625
2460
165
6.70732
278
Qtr3
7770
7300
470
6.43836
540
[ ]
If you are familiar with reports and are wondering why you may want to switch to MDX,
this section describes specific concepts in MDX
not available in reports.
1. Declarative query as input and set of structures as output
[ ]
East
Qtr2
Budget
Marketing
SELECT
{(Budget, Marketing)} on Columns,
Filter (
Product.Levels(0).Members,
(Qtr1, Actual, Sales) > 1000
) on Rows
WHERE (East, Qtr2)
100-10
490
200-10
910
200-40
310
300-10
390
300-20
250
400-10
130
400-30
90
SELECT
Children (East) on Columns,
Children (Colas) on Rows
FROM Sample.Basic
WHERE (Qtr1, Actual, Sales)
[ ]
3. MDX is not an end-user interface for churning out end-user reports from the Essbase
Server. Report writer has a rich formatting support and you can write a report to output the
query result in a presentable fashion. Of course,
you can also use the powerful Essbase spreadsheet Add-in interface to design robust Excel
spreadsheets to retrieve data from Essbase.
On the other hand, MDX lets the user specify the query and supports a set of APIs to
navigate over the query results. The Essbase
Multidimensional Access Language (MAXL),
[ ]
[ ]
Then the Slicer clause (i.e. singleton set definition in the WHERE clause), if present, is
processed. Member(s) corresponding to the
dimension(s) present in the slicer override the
default context to form the new MDX context.
This new context is used for the rest of the
MDX query execution. Note that the slicer
clause can only specify singleton members
from each dimension.
For example, the following query
SELECT
WHERE (EAST, QTR1)
[ ]
1. As an optimization the named-set definitions are processed only if they are later referenced in the query. If theyre not actually used,
Essbase spends no time building them.
SUM
MIN
MAX
AVG
NONEMPTYCOUNT
FILTER
TOPCOUNT
BOTTOMCOUNT
TOPSUM
BOTTOMSUM
TOPPERCENT
BOTTOMPERCENT
ORDER
GENERATE
[ ]
All the functions listed above take an expression argument like SUM. However, the expression type is different for each function. For
example, the ORDER function requires either a
numeric or string expression, GENERATE takes
a set as the second argument and the FILTER
function takes a conditional expression. The
expression is numeric for the remaining functions.
Logically, an iterative function works as follows:
1. For every tuple in input set
2. Begin
3. Save the current MDX context (C1)
4. Create new MDX context (C2) overriding
the iterating tuples on C1.
5. Evaluate the expression using C2
6. :
7. : Iterative function specific tasks e.g.
cumulatively add the values in case of SUM
8. Restore the saved context (C1) i.e. the current MDX context at this point is C1.
9. End
Now, let us consider an example to illustrate
the above logic in steps. The following query
sorts the Colas (i.e., Children of [100]) based on
Actual Sales in Qtr1 and displays the sorted
colas Budgeted Sales and Marketing in Qtr2
SELECT
CrossJoin ({Budget}, {Marketing,
Sales}) on Columns,
Order (Children ([100]), (Qtr1,
Actual)) on Rows
WHERE (Qtr2)
Qtr2
Market
Budget
Budget
Marketing
Sales
100-30
450
3400
100-20
1160
8800
100-10
1800
17230
[ ]
[ ]
WITH
MEMBER [Year].[Q1] as Jan + Feb + Mar
MEMBER [Measures].[M] as Margin * 100 / Sales
SELECT
{M} on Columns,
{Q1} on Rows
Where (Product, Market, Actual)
Product
Market
Actual
Margin
Sales
M = Margin * 100/Sales
Jan
17,378
31,538
55.1
Feb
17,762
32,069
55.38
Mar
17,803
32,213
55.26
52,943
95,820
???
[ ]
[ ]
Report writer and other interfaces like GridAPI use dynamic time series (DTS) members
defined in the outline along with another time
dimension member that specifies the latest
time-period. MDX does not recognize DTS
members defined in the Essbase outline directly. However, MDX can return the same value as
returned by requests such as Q-T-D(Aug) (i.e.
sum of the values up to month of August in the
current Quarter) through functions such as
QTD(), YTD(), etc.. These functions take the
time dimension member (that one would specify to identify the latest time period in the
report writer interface) as an argument.
Internally, MDX uses the generation number
for the corresponding Essbase member Q-TD/Y-T-D. For example, the MDX expression
QTD(Aug) returns the set of all time dimension
members of the generation of Aug up to and
AS
There are major differences in the way sorting commands work in MDX and report writer.
In report writer, there are different commands
to sort the members of a dimension and the
rows of a report. In MDX, there is one function
ORDER (<set>, <expression>) that performs
all sorting. It evaluates the input value expression iteratively for every tuple in the set, and the
expression can provide names, generation or
level numbers, property or cell values to compare. Furthermore, sorting on multiple criteria
can be carried out by nesting calls to Order. For
example, the following report snippet and
MDX snippet are logically equivalent:
[ ]
<SORTGEN
<IDESCENDANTS Market
ORDER (DESCENDANTS (Market),
Market.CURRENTMEMBER. GEN_NUMBER)
However, the report writer sorting commands are stateful. That is, once a sort command is specified in a script, the sorting
requirement will be applicable to all subsequent
member selection commands in the script. The
MDX Order() function, on the other hand, is
applied to the input set to the function, and the
result of the Order() function is a sorted set.
Any other set expressions appearing in the same
MDX query will not be effected by the presence
of a prior ORDER command. Thus while
<SORTNONE functionality is required in
report writer language, such a command is
meaningless in MDX.
Secondly, report writer sorting commands
are applied to the members added with a
member command such as <Children,
<Descendants, etc. The MDX Order() function
works for the entire input set, regardless of how
it was created. For example,
<SORTMBRNAMES
Nov
<Children Qtr1
in report writer returns members in the following order: Nov, Feb, Jan, Mar.
Whereas
Order ({ Nov, Children(Qtr1)},
Year.CurrentMember.Member_name)
The set definition along rows will be executed independently of the contents of what is
specified on Columns. Since the <numeric
[ ]
TopCount (
CrossJoin (Children (Market),
Descendants (Product)),
5,
(Budget, Dec)
)
Secondly, each of these report writer commands can be used once in a script in effect. If
two or more different commands (TOP/BOTTOM and ORDERBY) are specified, then all of
them have to work on the same row dimension
grouping. On the other hand, the equivalent
MDX functions have no dependency among
each other. For example, TOPCOUNT implementation has no assumption about the operations/functions used to create the input set.
Lastly, the report writer TOP/BOTTOM and
ORDERBY commands work on a group of
members from the innermost row dimension
by default, though the grouping dimension can
also be input explicitly. The equivalent MDX
functions
TOP(/BOTTOM)COUNT
or
ORDER have no such assumption about the
dimension grouping. For example, the following report will get Top 5 Products for every
market.
<Sym
<Column (Scenario, Year)
Actual Budget
Jan Dec
<Top ( 5, @DataCol(4))
<Row (Market, Product)
<children Market
<Idescendants Product
!
[ ]
Measures
East
East
East
East
East
West
West
West
West
West
South
South
South
South
South
Central
Central
Central
Central
Central
Product
100
100-10
400
200-40
Product
300
200
Diet
100
Product
100
100-10
Diet
200
Product
Diet
200
100
300
Actual
Jan
1732
924
837
466
267
2339
755
752
663
378
997
329
244
355
480
2956
1080
751
724
790
Actual
Dec
2037
1026
867
501
383
2448
971
820
629
223
1141
432
327
404
496
3154
1064
753
792
824
Budget
Jan
2080
960
860
600
310
2980
830
850
850
830
1330
540
370
490
520
3550
1340
1060
900
930
Budget
Dec
2120
990
830
580
400
2710
950
860
730
530
1270
640
460
430
390
3570
1300
1220
890
810
[ ]
[ ]
<COLUMN
<PAGE
<ROW
On
On
On
On
On
On
COLUMNS
ROWS
PAGES
CHAPTERS
SECTIONS
AXIS (n) where n is the axis number
<ASYM
<SYM
[ ]
[ ]
<SORTNONE
<SORTASC
<SORTDESC
<SORTGEN
<SORTLEVEL
<SORTMBRNAMES
<SORTALTNAMES
[ ]
<TOP TOPCOUNT
( set , index
[,numeric_value_expression ] )
[ ]
[ ]
All Column or Row
Calculation commands
MDX does not support any such commands. Calculated members can be used
to perform custom calculations in query.
[ ]
OutMbrAlt
OutAltMbr
OutAlt
OutAltNames
OutAltSelect
1 Note that Hyperion also supports the production of MDX results in XML format through its support for XML for Analysis (XMLA). XMLA opens up new possibilities in the integration of
Essbase-held information in an enterprise. This paper will not discuss XMLA; please refer to the
XML for Analysis API Reference in the Essbase Deployment Services technical documentation.
, ..
Hyperion is the global leader in Business Performance
Management software. More than 9,000 customers including 91 of the FORTUNE 100 rely on Hyperion software to
translate strategies into plans, monitor execution and provide
insight to improve financial and operational performance.
Hyperion combines the most complete set of interoperable
applications with the leading business intelligence platform to
support and create Business Performance Management
solutions. A network of more than 600 partners provides the
companys innovative and specialized solutions and services.
. .
. .
. .
2004 Hyperion Solutions Corporation. All rights reserved. Hyperion, the Hyperion H logo and Hyperions product names are trademarks of Hyperion. References to other
companies and their products use trademarks owned by the respective companies and are for reference purpose only. 4247_0204