SlideShare una empresa de Scribd logo
1 de 18
Digvendra Singh
   Introduction
    ◦ What is MDX
    ◦ Where MDX is required
   Syntax and examples on MDX
   Basics of MDX
       Axis
       Member Reference
       Tuple
       Partial Tuple
       Sets
       Calculated Members
       Calculated Sets
   Functions
   Different reporting scenarios
   MDX is a language used for querying and
    manipulating data stored in OLAP Cubes (or say
    multi-dimensional databases)

   Concept is same as “SQL is a querying language”.
    ◦ SQL  Relational Database
    ◦ MDX  Multidimensional Database

   MDX return multidimensional cell-sets that contain
    the cube's data
OLAP Cube             Result (multidimensional
                      Cube-Sets)




            MDX




                  Reporting Services
                  (SSRS, SAP TM1, Oracle Essbase,
                  Microstrategy, Tableau, Cognos etc.)
Syntax:
  [ WITH <SELECT WITH clause> [ , <SELECT WITH clause>
  ... ] ]
  SELECT [ * | ( <SELECT query axis clause>
      [ , <SELECT query axis clause> ... ] ) ]
  FROM <SELECT subcube clause>
  [ <SELECT slicer axis clause> ]
  [ <SELECT cell property list clause> ]



Simplest Syntax:
  SELECT {set} ON AXIS(0)
  ,        {set} ON AXIS(1)
  FROM [Cube]
  WHERE <<data is sliced by some coordinates>>
Before getting into details, you should be familiar with basics of Cube
terminology. This include Cube, Measures, Attribute Hierarchy,
Members, Level etc.
For revision please refer the link below:
http://bistuffwithdigven.wordpress.com/2012/10/10/cube-browsing/
a.   Axis
b.   Member Reference
c.   Tuple
d.   Partial Tuple
e.   Sets
f.   Calculated Members
g.   Calculated Sets
   Axes in MDX defines representation plane for data of result
    set. Sometimes we put one dimension representing one axis.
         For e.g. in 3-D space x,y,z are three axes (figure below)
   In SELECT statement we specify what data on which axes of
    result-set, is required
   SELECT statement support 128 axes (i.e. 0 to 127)
   Important axes in MDX are listed below (most used are 0 and
    1):
       Formal Name   Short Name   Alias

       Axis(0)       0            COLUMNS
       Axis(1)       1            ROWS
       Axis(2)       2            PAGES
       Axis(3)       3            SECTIONS
       Axis(4)       4            CHAPTERS
   Fully qualified name for each member in Cube
   Multiple ways to give member reference:
   [Dimension].[Attribute Hierarchy].[Attribute].[Member]

   Without user hierarchy (Attribute Hierarchy is Attribute itself)
   E.g.
    ◦   [Time].[Year].[Year].[2001]
    ◦   [Time].[Year].[Year].&[2001]
    ◦   [Time].[Year].[Year].&[1]
   With user hierarchy
   E.g.
    ◦   [Time].[Fiscal].[Year].[2001]
    ◦   [Time].[Calendar].[Year].&[2001]
    ◦   [Time].[Fiscal].[Year].&[1]
   We need not Attribute name sometimes
   E.g.
    ◦   [Time].[Year].[2001]
    ◦   [Time].[Calendar].[Year].[2001]
   Ordered list of members from each dimensions of cube
         Represent a point in the Cube space
         A cell can be representation of a tuple
         For e.g.
          ◦ In 3-D space (x1, y1, z1) is a tuple
          ◦ In a cube with 3 dimensions (2 dimensions and 1 for measures)
          ([Time].[Year].[Year].[2001], [Product].[Category].[Category].[Bikes], [Measures].[Sales Amount]) is a tuple
•    In 3-D space, a tuple represent list of one member from
    each axis. So an ordered members list says (x1, y1, z1) .
    <In Red>

•    In Cube a tuple is ordered list of member from each
    dimension (more specifically each attribute of cube). In
    this example we believe there are 2 Dimension only and 1
    member from Measures Dimension is necessary. <In Blue>
   Part of the tuple with less member reference, where rest of
    the member reference are taken care with Analysis Services to
    understand

   That is, no need to list for all the members from each
    dimension

   Default member from dimension is used in place of Omitted
    members

   For e.g.
    ◦ In 3-D space, if we want to omit an axis tuple will be (0, y1, z1) i.e. with
      zero
    ◦ In Cube space, if we omit Time dimension tuple will be
      ([Product].[Category].[Category].[Bikes], [Measures].[Sales Amount])
   Ordered collection of tuples with the same
    dimensionality, or hierarchality
   E.g.
   Sets with tuple having single member:
   {[Time].[Year].[2001], [Time].[Year].[2007], [Time].[Year].[2009]}


   Sets with tuple having multiple members:
   { (Time.[Year].[Year].[2001], [Product].[Category].[Category].[Bikes]),
    (Time.[Year].[Year].[2002], [Product].[Category].[Category].[Clothing]) }


   Sets with hierarchy involved:
    { (Time.[Fiscal].[Year].[2001], [Product].[Category].[Category].[Bikes]),
    (Time.[Fiscal].[Year].[2002], [Product].[Category].[Category].[Clothing]) }
   MDX provide way to create and query calculated members in
    result set
   Use WITH MEMBER clause before SELECT statement
   Create a member in any dimensional attribute and Measures
    dimension as well.

   E.g. Dimensional Member:
    WITH MEMBER [Product].[Category].[Popular] AS
    [Product].[Category].[Category].[Bikes]+[Product].[Category].[Category].[Clothing
    ]
   E.g. Measures member (new calculated measure):
    WITH
    MEMBER [Total Sales] AS
    ([Measures].[Reseller Sales Amount]+ [Measures].[Internet Sales Amount])
   Same as Named Sets in Cube, we can create Calculated Sets in
    MDX while querying
   Sets are always collection of Tuples, so is a calculated set
   Use WITH SET clause before SELECT statement

   E.g. Calculated set for two members of Product Category:
    WITH SET [Best Products] AS
    {[Product].[Category].[Category].[Bikes],[Product].[Category].[Cat
    egory].[Clothing]}
   About 12-13 categories and more than 50
    Functions
   Functions eases the calculations and provide
    desired results
   Need to understand function with examples and
    their uses
   Broad categories are :
    ◦   Set Functions
    ◦   Navigation Functions
    ◦   Metadata Functions
    ◦   Time Functions
    ◦   String Functions
    ◦   UI Functions
   Different reporting requirements needs different MDX
    query manipulation
   For example:
    ◦ We list all or selected members of one attribute to fill filter values of report
    ◦ We CROSSJOIN different attributes to get multiple columns or fields
      required in report
    ◦ We use NON EMPTY to filter unnecessary rows from results
    ◦ We use STRTOSET, STRTOMEMBER to manipulate string as cube members
    ◦ We create calculated members and sets when desired fields are not
      available in cube
    ◦ We use SUBCUBE functions and queries in MDX to avoid unwanted totals


There are many different scenarios coming across reporting needs.
But I am sure little hands on experience with MDX, can help you
find solution for all. That’s the beauty of MDX, its flexible and vast.
   Please add all your queries and doubt here or
    my blog:
   http://bistuffwithdigven.wordpress.com/

   For further details on functions and MDX please
    comment on the blog posts.

Más contenido relacionado

La actualidad más candente (20)

Sql commands
Sql commandsSql commands
Sql commands
 
SQL DDL
SQL DDLSQL DDL
SQL DDL
 
Oltp vs olap
Oltp vs olapOltp vs olap
Oltp vs olap
 
SQL report
SQL reportSQL report
SQL report
 
SSIS Presentation
SSIS PresentationSSIS Presentation
SSIS Presentation
 
DBMS Notes: DDL DML DCL
DBMS Notes: DDL DML DCLDBMS Notes: DDL DML DCL
DBMS Notes: DDL DML DCL
 
Data partitioning
Data partitioningData partitioning
Data partitioning
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
Oracle: DDL
Oracle: DDLOracle: DDL
Oracle: DDL
 
What Is DATA MINING(INTRODUCTION)
What Is DATA MINING(INTRODUCTION)What Is DATA MINING(INTRODUCTION)
What Is DATA MINING(INTRODUCTION)
 
Data analytics
Data analyticsData analytics
Data analytics
 
Data mining query languages
Data mining query languagesData mining query languages
Data mining query languages
 
PL-SQL, Cursors & Triggers
PL-SQL, Cursors & TriggersPL-SQL, Cursors & Triggers
PL-SQL, Cursors & Triggers
 
Data warehouse 21 snowflake schema
Data warehouse 21 snowflake schemaData warehouse 21 snowflake schema
Data warehouse 21 snowflake schema
 
MYSQL-Database
MYSQL-DatabaseMYSQL-Database
MYSQL-Database
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
Star schema PPT
Star schema PPTStar schema PPT
Star schema PPT
 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)
 

Similar a MDX (Multi Dimensional Expressions) Introduction

Introducing ms sql_server_updated
Introducing ms sql_server_updatedIntroducing ms sql_server_updated
Introducing ms sql_server_updatedleetinhf
 
Getting Started with MDX 20140625a
Getting Started with MDX 20140625aGetting Started with MDX 20140625a
Getting Started with MDX 20140625aRon Moore
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowPavithSingh
 
Oracle Database Advanced Querying (2016)
Oracle Database Advanced Querying (2016)Oracle Database Advanced Querying (2016)
Oracle Database Advanced Querying (2016)Zohar Elkayam
 
Islamic University Previous Year Question Solution 2018 (ADBMS)
Islamic University Previous Year Question Solution 2018 (ADBMS)Islamic University Previous Year Question Solution 2018 (ADBMS)
Islamic University Previous Year Question Solution 2018 (ADBMS)Rakibul Hasan Pranto
 
Ms sql server architecture
Ms sql server architectureMs sql server architecture
Ms sql server architectureAjeet Singh
 
Introduction To Oracle Sql
Introduction To Oracle SqlIntroduction To Oracle Sql
Introduction To Oracle SqlAhmed Yaseen
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorialAxmed Mo.
 
With big data comes big responsibility
With big data comes big responsibilityWith big data comes big responsibility
With big data comes big responsibilityERPScan
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsZohar Elkayam
 

Similar a MDX (Multi Dimensional Expressions) Introduction (20)

Module02
Module02Module02
Module02
 
Mdx basics
Mdx basicsMdx basics
Mdx basics
 
Mdx Basics
Mdx BasicsMdx Basics
Mdx Basics
 
PT- Oracle session01
PT- Oracle session01 PT- Oracle session01
PT- Oracle session01
 
Vertica-Database
Vertica-DatabaseVertica-Database
Vertica-Database
 
Introducing ms sql_server_updated
Introducing ms sql_server_updatedIntroducing ms sql_server_updated
Introducing ms sql_server_updated
 
Getting Started with MDX 20140625a
Getting Started with MDX 20140625aGetting Started with MDX 20140625a
Getting Started with MDX 20140625a
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
 
Sql
SqlSql
Sql
 
Oracle Database Advanced Querying (2016)
Oracle Database Advanced Querying (2016)Oracle Database Advanced Querying (2016)
Oracle Database Advanced Querying (2016)
 
Islamic University Previous Year Question Solution 2018 (ADBMS)
Islamic University Previous Year Question Solution 2018 (ADBMS)Islamic University Previous Year Question Solution 2018 (ADBMS)
Islamic University Previous Year Question Solution 2018 (ADBMS)
 
Ms sql server architecture
Ms sql server architectureMs sql server architecture
Ms sql server architecture
 
Less08 Schema
Less08 SchemaLess08 Schema
Less08 Schema
 
Introduction To Oracle Sql
Introduction To Oracle SqlIntroduction To Oracle Sql
Introduction To Oracle Sql
 
Dbms sql-final
Dbms  sql-finalDbms  sql-final
Dbms sql-final
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
Les09
Les09Les09
Les09
 
With big data comes big responsibility
With big data comes big responsibilityWith big data comes big responsibility
With big data comes big responsibility
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic Functions
 

MDX (Multi Dimensional Expressions) Introduction

  • 2. Introduction ◦ What is MDX ◦ Where MDX is required  Syntax and examples on MDX  Basics of MDX  Axis  Member Reference  Tuple  Partial Tuple  Sets  Calculated Members  Calculated Sets  Functions  Different reporting scenarios
  • 3. MDX is a language used for querying and manipulating data stored in OLAP Cubes (or say multi-dimensional databases)  Concept is same as “SQL is a querying language”. ◦ SQL  Relational Database ◦ MDX  Multidimensional Database  MDX return multidimensional cell-sets that contain the cube's data
  • 4.
  • 5. OLAP Cube Result (multidimensional Cube-Sets) MDX Reporting Services (SSRS, SAP TM1, Oracle Essbase, Microstrategy, Tableau, Cognos etc.)
  • 6. Syntax: [ WITH <SELECT WITH clause> [ , <SELECT WITH clause> ... ] ] SELECT [ * | ( <SELECT query axis clause> [ , <SELECT query axis clause> ... ] ) ] FROM <SELECT subcube clause> [ <SELECT slicer axis clause> ] [ <SELECT cell property list clause> ] Simplest Syntax: SELECT {set} ON AXIS(0) , {set} ON AXIS(1) FROM [Cube] WHERE <<data is sliced by some coordinates>>
  • 7. Before getting into details, you should be familiar with basics of Cube terminology. This include Cube, Measures, Attribute Hierarchy, Members, Level etc. For revision please refer the link below: http://bistuffwithdigven.wordpress.com/2012/10/10/cube-browsing/
  • 8. a. Axis b. Member Reference c. Tuple d. Partial Tuple e. Sets f. Calculated Members g. Calculated Sets
  • 9. Axes in MDX defines representation plane for data of result set. Sometimes we put one dimension representing one axis. For e.g. in 3-D space x,y,z are three axes (figure below)  In SELECT statement we specify what data on which axes of result-set, is required  SELECT statement support 128 axes (i.e. 0 to 127)  Important axes in MDX are listed below (most used are 0 and 1): Formal Name Short Name Alias Axis(0) 0 COLUMNS Axis(1) 1 ROWS Axis(2) 2 PAGES Axis(3) 3 SECTIONS Axis(4) 4 CHAPTERS
  • 10. Fully qualified name for each member in Cube  Multiple ways to give member reference:  [Dimension].[Attribute Hierarchy].[Attribute].[Member]  Without user hierarchy (Attribute Hierarchy is Attribute itself)  E.g. ◦ [Time].[Year].[Year].[2001] ◦ [Time].[Year].[Year].&[2001] ◦ [Time].[Year].[Year].&[1]  With user hierarchy  E.g. ◦ [Time].[Fiscal].[Year].[2001] ◦ [Time].[Calendar].[Year].&[2001] ◦ [Time].[Fiscal].[Year].&[1]  We need not Attribute name sometimes  E.g. ◦ [Time].[Year].[2001] ◦ [Time].[Calendar].[Year].[2001]
  • 11. Ordered list of members from each dimensions of cube  Represent a point in the Cube space  A cell can be representation of a tuple  For e.g. ◦ In 3-D space (x1, y1, z1) is a tuple ◦ In a cube with 3 dimensions (2 dimensions and 1 for measures) ([Time].[Year].[Year].[2001], [Product].[Category].[Category].[Bikes], [Measures].[Sales Amount]) is a tuple • In 3-D space, a tuple represent list of one member from each axis. So an ordered members list says (x1, y1, z1) . <In Red> • In Cube a tuple is ordered list of member from each dimension (more specifically each attribute of cube). In this example we believe there are 2 Dimension only and 1 member from Measures Dimension is necessary. <In Blue>
  • 12. Part of the tuple with less member reference, where rest of the member reference are taken care with Analysis Services to understand  That is, no need to list for all the members from each dimension  Default member from dimension is used in place of Omitted members  For e.g. ◦ In 3-D space, if we want to omit an axis tuple will be (0, y1, z1) i.e. with zero ◦ In Cube space, if we omit Time dimension tuple will be ([Product].[Category].[Category].[Bikes], [Measures].[Sales Amount])
  • 13. Ordered collection of tuples with the same dimensionality, or hierarchality  E.g.  Sets with tuple having single member:  {[Time].[Year].[2001], [Time].[Year].[2007], [Time].[Year].[2009]}  Sets with tuple having multiple members:  { (Time.[Year].[Year].[2001], [Product].[Category].[Category].[Bikes]), (Time.[Year].[Year].[2002], [Product].[Category].[Category].[Clothing]) }  Sets with hierarchy involved:  { (Time.[Fiscal].[Year].[2001], [Product].[Category].[Category].[Bikes]), (Time.[Fiscal].[Year].[2002], [Product].[Category].[Category].[Clothing]) }
  • 14. MDX provide way to create and query calculated members in result set  Use WITH MEMBER clause before SELECT statement  Create a member in any dimensional attribute and Measures dimension as well.  E.g. Dimensional Member: WITH MEMBER [Product].[Category].[Popular] AS [Product].[Category].[Category].[Bikes]+[Product].[Category].[Category].[Clothing ]  E.g. Measures member (new calculated measure): WITH MEMBER [Total Sales] AS ([Measures].[Reseller Sales Amount]+ [Measures].[Internet Sales Amount])
  • 15. Same as Named Sets in Cube, we can create Calculated Sets in MDX while querying  Sets are always collection of Tuples, so is a calculated set  Use WITH SET clause before SELECT statement  E.g. Calculated set for two members of Product Category: WITH SET [Best Products] AS {[Product].[Category].[Category].[Bikes],[Product].[Category].[Cat egory].[Clothing]}
  • 16. About 12-13 categories and more than 50 Functions  Functions eases the calculations and provide desired results  Need to understand function with examples and their uses  Broad categories are : ◦ Set Functions ◦ Navigation Functions ◦ Metadata Functions ◦ Time Functions ◦ String Functions ◦ UI Functions
  • 17. Different reporting requirements needs different MDX query manipulation  For example: ◦ We list all or selected members of one attribute to fill filter values of report ◦ We CROSSJOIN different attributes to get multiple columns or fields required in report ◦ We use NON EMPTY to filter unnecessary rows from results ◦ We use STRTOSET, STRTOMEMBER to manipulate string as cube members ◦ We create calculated members and sets when desired fields are not available in cube ◦ We use SUBCUBE functions and queries in MDX to avoid unwanted totals There are many different scenarios coming across reporting needs. But I am sure little hands on experience with MDX, can help you find solution for all. That’s the beauty of MDX, its flexible and vast.
  • 18. Please add all your queries and doubt here or my blog:  http://bistuffwithdigven.wordpress.com/  For further details on functions and MDX please comment on the blog posts.