Date post: | 29-Nov-2014 |
Category: |
Technology |
Upload: | edarsoft |
View: | 1,530 times |
Download: | 3 times |
MDX Language An Overview
Presented by:
Muhammad Saleh AL-Qurishi Fatooh AL-Qershi
204/09/2023
Agenda Introduction
Brief HistorySQL vs. MDX
MDX LanguageMDX syntaxNaming conventionsTuples and sets
How MDX is usedMDX queries
Using MDX for queriesSELECT, FROM, ON COLUMNS, ON ROWSWHERE
MDX expression References
MDX Solution Presentation By-Muhammad & Fatooh
304/09/2023 MDX Solution Presentation By-Muhammad & Fatooh
Introduction
404/09/2023
Brief History
MDX Solution Presentation By-Muhammad & Fatooh
When first conceived of by Panorama Software in the mid-1990s, MDX was an extension of SQL.
Its original name was Multi-Dimensional eXtensions, (says Mosha Pasumansky)
In less than a decade, the programming language MDX has become the de facto standard for reporting and analysis in business intelligence (BI) systems
It is supported by virtually every major vendor of BI servers, including Microsoft, SSAS, IBM, Hyperion, and SAP
504/09/2023
Why has MDX become so popular
The growth of the BI industry it self.Users need fast and intuitive access to company
information to make more profitable business decisions
It is uniquely able to navigate, query, and perform calculations against multidimensional structures
MDX Solution Presentation By-Muhammad & Fatooh
604/09/2023
How MDX Differs from SQL?SQL MDX
Designed to create, manage, and query relational databases in online transaction (OLTP) systems
Developed to navigate, query, and perform calculations in OLAP databases
Select, From, WhereSELECT <column 1>, <column 2>, <column n> FROM <table>
Select, From, WhereSELECT <axis specification> on columns, <axis specification> on rows FROM <cube>
WHERE clause is used to restrict (filter) the rows
WHERE clause points to a specific slice of an OLAP cube
Two dimensional result Multi-dimensional result
Select from relations Select from cubes
Rows in SQL are defined by the columns The columns do not define the rows and vice versa
Functions such as AVG, COUNT, MIN, MAX, SUM, STDEV, and VAR
Functions such as AVG, COUNT, MIN, MAX, SUM, STDEV, and VAR
MDX Solution Presentation By-Muhammad & Fatooh
704/09/2023
SQL Does Things that MDX Can’t
SQL is self-contained
•It is a data definition
language (DDL) for
•It is a data manipulation
language (DML)
MDX has almost no data
definition capabilities
•You can’t create an OLAP cube
using MDX
MDX and SQL work hand-in-
hand in BI applications,
each doing its part to support
self-service reporting and
analytics
MDX Solution Presentation By-Muhammad & Fatooh
804/09/2023
MDX Language
MDX Solution Presentation By-Muhammad & Fatooh
904/09/2023
What Is MDX? MDX is a language that
Expresses selections, calculations, and some metadata definitions against an Online Analytical Processing (OLAP) database
Provides some capabilities for specifying how query results are to be represented
Is not a full report-formatting languageThere are several different APIs that support MDX
OLE DB for OLAP, ADO MD, ADOMD.Net, XMLA
MDX Solution Presentation By-Muhammad & Fatooh
1004/09/2023
MDX – Basic Terminology Cube – is a subset of data from the OLAP store, organized and
summarized into multidimensional structures Cell – One or more facts (measures) and dimension attributes that
represent one record in a cube Dimension – business factor used to group a fact record Hierarchy – Levels of aggregation in a dimension Level – Aggregation layer in a dimension hierarchy Member – value of a dimension attribute or a derived value from a
dimension attribute Measure – Fact. Numerical value that measures a business activity
and can be summarized MDX Solution Presentation By-Muhammad & Fatooh
1104/09/2023
Naming Conventions
MDX Solution Presentation By-Muhammad & Fatooh
Working with the Store dimension shown in the diagram above, we’d indicate the Leominster member like this:
[Store].[All].[Massachusetts].[Leominster]
[Store].Leominster] with certain data and certain naming conventions
if we have a hierarchy of Time we can’t use [Time].[Oct] because we may have more than one October in different years. But we can use [Time].[June,2001] rather than [Time].[All].[2001].[Q2].[June]
1204/09/2023
Tuples and SetsA tuple is a combination of members from different
dimensions Essentially a multidimensional member A single member is a simple tuple
([Time].[Jun, 2005]) simple tuple (one dimension) ([Customer].[Chicago, IL], [Time].[Jan, 2005]) tuple with two
dimensions Each member in the tuple has to be from a different
dimension E.g. tuple should not have two Time members
We can’t compose an empty tuple We can’t use syntax to compose a tuple from tuples
MDX Solution Presentation By-Muhammad & Fatooh
1304/09/2023
Tuples and Sets(cont.)
A set is simply an ordered collection of tuples Sets are typically enclosed by curled "{ }" braces Specify the cells of a cube that are to be returned by the
query Often appear in the SELECT part of a query
MDX Solution Presentation By-Muhammad & Fatooh
SELECT{ ( [Time].[2005], [Measures].[Dollar Sales] ),( [Time].[Feb, 2005], [Measures].[Unit Sales] )}ON COLUMNS ,{ [Product].[Tools], [Product].[Toys] } ON ROWSFROM [Sales]
1404/09/2023
Brackets, braces and the odd dot and comma
MDX Solution Presentation By-Muhammad & Fatooh
•Dimension and member names are enclosed within brackets [ ] especially if the name contains numbers,
spaces, other special characters or is a keywordBrackets[ ]
•To separate the dimension name from the member name. (to represent the hierarchy)•]Product[.]Drink[.]Beverages[Dots . – Separators
•Used to denote tuples•)]Product].[Drink].[Beverages[(Braces ( ) – Tuples
•Used to denote sets•Slide 6
Curly braces { } – Sets
•For range the constructionthe colon) : (
•To separate tuples in the setComma) ,(
1504/09/2023
Question 1
MDX Solution Presentation By-Muhammad & Fatooh
Is the following a tuple or a set?([Time].[May], [Store].[Boston], [Product].[Anchovies])
Answer: ?
1604/09/2023
Question 2 OK, now what about these two?
1- ([Store].[Boston], [Product].[Anchovies])
2- {([Time].[April], [Store].[Boston], [Product].[Anchovies]),
([Time].[May], [Store].[Boston], [Product].[Anchovies]),
([Time].[June], [Store].[Boston], [Product].[Anchovies]),
([Time].[July], [Store].[Boston], [Product].[Anchovies])}
Answer:?
MDX Solution Presentation By-Muhammad & Fatooh
1704/09/2023
How MDX is used
MDX Solution Presentation By-Muhammad & Fatooh
1804/09/2023
MDX Query SyntaxSELECT
{set defining the column headers}
ON COLUMNS,
{set defining the row headers}
ON ROWS
FROM [cube name]
WHERE [Slicer specification]
MDX Solution Presentation By-Muhammad & Fatooh
MDX is neither case-sensitive nor line-oriented
1904/09/2023
MDX Query Syntax(cont.)
N Axes
0 Columns
1 Rows
2 Pages
3 Chapters
4 Sections
MDX Solution Presentation By-Muhammad & Fatooh
The phrase on axis(n) indicates that those members should be put on the axis numbered n.
A query that uses axis 1 must also use axis 0, and a query that uses axis 2 must also use axes 1 and 0
The SELECT keyword starts the clause that specifies what you want to retrieve
The ON keyword is used with an axis name to specify where dimensions from our database are displayed
If you desire more generic axis terms over the named terms, you can use the AXIS(index) naming convention
2004/09/2023
Query example
MDX Solution Presentation By-Muhammad & Fatooh
SELECT{ [Measures].[Dollar Sales], [Measures].[Unit Sales] }ON columns,{ [Time].[Q1, 2005], [Time].[Q2, 2005] }ON rowsFROM [Sales]
Look at a grid of numbers that has the Massachusetts sales and costs for the first two quarters of 2005
2104/09/2023
Slicer Clause (WHERE clause) WHERE clause is actually optional It is used to define the measure that is being
queried It can, and often does, extend to other dimensions
WHERE (Measures.[Sales Average], [Time].[Year].[1997])
It is not the same as filtering (such as SQL)Slicing does not affect selection of the axis members,
but rather the values that go into themFiltering reduces the number of axis members
MDX Solution Presentation By-Muhammad & Fatooh
2204/09/2023
Five main execution stages after the query is successfully parsed:
1- Resolving the FROM clause
2- Resolving the WHERE clause
3- Resolving named sets in the WITH clause
4- Resolving the tuples on each axis
5- Calculating the cells brought back in the axis intersections
a. Resolving NON EMPTY intersections
b. (AS2005) Resolving the HAVING clause on each axis
MDX Solution Presentation By-Muhammad & Fatooh
The Execution Stages of a Query
2304/09/2023
MDX Expression
MDX Solution Presentation By-Muhammad & Fatooh
2404/09/2023
Calculated Member The core syntax for defining a calculated member on a
dimension is MEMBER MemberIdentifier AS ‘member-formula’ [,
properties...] The three main parts are:
Member identifier, which specifies the name, dimension and hierarchical positioning of the calculated member
Formula, which specifies how the calculated member’s results are derived
Optional properties, which can provide additional calculation, display, and other kinds of information
MDX Solution Presentation By-Muhammad & Fatooh
2504/09/2023
Calculated Member(cont.)
Calculated Member in the WITH section of a query will not visible outside of the query.
If we use CREATE SET command, then it will be available to more than one query
We can drop it with the DROP SET command
MDX Solution Presentation By-Muhammad & Fatooh
2604/09/2023
Calculated Member(WITH Section)
MDX Solution Presentation By-Muhammad & Fatooh
2704/09/2023
Calculated Member(more than one dimension)
MDX Solution Presentation By-Muhammad & Fatooh
2804/09/2023
Named Set The basic syntax for defining a named set that is
supported by most vendors is as follows:SET Set-Identifier AS ‘set-formula’
Named set in the WITH part of a query will not visible outside of the query.
If we use CREATE SET command, then it will be available to more than one query
We can drop it with the DROP SET command
MDX Solution Presentation By-Muhammad & Fatooh
2904/09/2023
Named set using WITH clause
MDX Solution Presentation By-Muhammad & Fatooh
3004/09/2023
Named set using CREAT SET
MDX Solution Presentation By-Muhammad & Fatooh
Analysis Services 2005
Essbase V9
3104/09/2023
Common Functions
MDX Solution Presentation By-Muhammad & Fatooh
3204/09/2023
.MEMBER The simplest form of an axis specification or
member selection involves taking the MEMBERS of the required dimensionReturns set of all members
MDX Solution Presentation By-Muhammad & Fatooh
SELECT Measures.MEMBERS ON COLUMNS,[Store].MEMBERS ON ROWSFROM [Sales]
SELECT Measures.MEMBERS ON COLUMNS,{[Store].[Store State].[CA], [Store].[Store State].[WA]} ON ROWSFROM [Sales]
3304/09/2023
. CHILDREN Returns the set of all members of the level
immediately beneath the starting levelReturns the child members for a particular member
within the dimension
MDX Solution Presentation By-Muhammad & Fatooh
SELECT Measures.MEMBERS ON COLUMNS,{[Store].[Store State].[CA].CHILDREN,[Store].[Store State].[WA].CHILDREN} ON ROWSFROM [Sales]
3404/09/2023
Both MEMBER & CHILDREN functions are used often in formulating expressions, but do not provide the ability to drill down to a lower level within the hierarchy
MDX Solution Presentation By-Muhammad & Fatooh
For this task, a function called DESCENDANTS is requiredThis function allows one to go to any level in depth
3504/09/2023
Descendants()
MDX Solution Presentation By-Muhammad & Fatooh
The expression:Descendants( [Time].[1998],[Month])would return all twelve months 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 and 12 (that is, all the descendants of 1998 at the month level) And:Descendants( [Time].[1998].[Q2],[Month])would return all the descendants of Q2 at the month level, namely 4, 5 and 6
The syntax for the DESCENDANTS function is:DESCENDANTS(member, level [, flags])
3604/09/2023
CrossJoin() CrossJoin() – cross-product of members or
tuples in two different sets Specify all possible combinations Syntax: CrossJoin (set1, set2)
MDX Solution Presentation By-Muhammad & Fatooh
3704/09/2023
Filter() Reduce a set by including in the resulting set only those
elements that meet some criteria Arguments
Boolean Expression Set
Returns subset The syntax for Filter() is:
Filter (set, Boolean-expression) For example, the expression
Filter (
{ [Product].[Product Category].Members },
[Measures].[Dollar Sales] >= 500
)
MDX Solution Presentation By-Muhammad & Fatooh
3804/09/2023
Order() To put the tuples in a set into a sequence based
on associated data values The syntax for the Order() function
Order (set1, expression [, ASC | DESC | BASC | BDESC])
Arguments Ordering criterion Set Flag option (ex. Ascending, descending)
Hierarchical order can be complex MDX Solution Presentation By-Muhammad & Fatooh
3904/09/2023
Order() Example Given the set of product categories , we may want to sort them in
descending order by sales. A very simple query for this may look like the following;
MDX Solution Presentation By-Muhammad & Fatooh
4004/09/2023
NON EMPTY Removing empty slices from query results Works on any axis, and with any dimensions and tuples
MDX Solution Presentation By-Muhammad & Fatooh
4104/09/2023
NON EMPTY
MDX Solution Presentation By-Muhammad & Fatooh
Query with empty slices on rows Empty slices removed with NON EMPTY
4204/09/2023
References MDX Solutions, Second Edition: With Microsoft® SQL Server™ Analysis Services
2005 and Hyperion® Essbase Fast Track to MDX by Mark Whitehorn, Robert Zare and Mosha Pasumansky MDX language reference http://msdn.microsoft.com/en-us/library/ms145506.aspx http://www.databasejournal.com/article.php/1459531
MDX Solution Presentation By-Muhammad & Fatooh
4304/09/2023
Thanks
? MDX Solution Presentation By-Muhammad & Fatooh