Multidimensional Data Expressions MDX Notes

#####Overview
1. MDX (Multidimensional Expression) supports the definition and operation of multidimensional objects and data. Not an extension of SQL.
2. MDX queries all require select, from, and where clauses.
3. MDX provides DDL syntax for managing data structures, including commands to create and delete cubes, dimensions, measures, and their coordinate objects.

####Basic Concepts
1. MDX returns a subset of cubes from a cube.
    Unit: The object determined by the intersection of the coordinate axes. Uniquely identifies the smallest cell in a cube.
          Each cell has multiple pieces of information associated with it, including the data itself, the format string (an explicit format for cell data), and the cell's ordinal number.
          
    Tuple: An ordered collection consisting of a single member from one or more dimensions. Uniquely identifies a portion of a cube that defines a slice or dice of data from the cube.
          A tuple is a vector of members, and if it consists of members from more than one dimension, the members represented by the tuple must be enclosed in parentheses.
          
    Set: An ordered collection of zero, one or more tuples.
          Collections need to be enclosed in curly braces.
          ****Tuples in a collection must have the same dimension order. **** 2.    A set of tuples consisting of members of the different dimensions of the
          
axis dimension and slicer dimension (slicing criteria) are used to filter the cube data.
The select statement is used to select the dimensions and members to return - axis dimension (returns data for multiple members)
   
   where statement is used to limit the returned data to specific dimensions and member conditions - slicer dimension (returns data for a single member)
   ***If no dimension is explicitly assigned to the slicer, the default member is used for filtering.
   If the "All" level exists, the default member is "All", otherwise it is any member of the highest level. ***
   
   SELECT <axis info> on columns
          <axis info> on rows
   from <cube>
   where <slice condition>
   
3. Calculate members
   based on the value in MDX to express the members of the book

4. User Defined Functions
    
5. PivotTable Services
    MDX data definition and manipulation services are provided through PivotTable Services
    
6. Member Functions
    MDX provides many functions to retrieve members from other dimensions or levels (MDX entities).
    As FirstChild allows to retrieve the first child member from a given dimension or level The
    Members function returns a collection of members in the dimension, level or hierarchy.

7. Aggregate function
    colon operator uses Chen Guan's natural order to create sets such as {[first quarter]:[fourth quarter]}
    

######The main features of MDX relative to SQL (the operation object is a cube)
1. MDX can query data in any multi-dimensional data structure
2. The select clause can define several axis dimensions, and the where clause can Used to restrict multidimensional data to specific dimensions or members.
3. The creator of an MDX query usually visualizes and defines the structure of a cube, and writes a query on a single cube to populate that structure.
OLAP schema includes cubes, measures, dimensions, levels, members, Hierarchy, and member attribute information. There is a corresponding representation in the MDX query.

Dimensions and measures: they are unique within the same cube, so they can be represented directly by name
Hierarchy: the dimension he belongs to is prefixed with a period, followed by his name
Level: the dimension name in square brackets , followed by the name of the hierarchy in square brackets, followed by the name of the level, separated by periods.
Member: The member name of all levels above the level to which the member to be accessed must be added one by one along the hierarchy of the dimension
Member attribute: In order to uniquely identify a member attribute, its name needs to be added after the level to which it belongs, followed by a dot separated by number

####Using Square Brackets
There are two ways to refer to individual item names in a schema in MDX
1. Use square brackets []
2. Do not use square brackets, refer to item names directly.
If the name of an item in the referenced schema contains spaces, you must use square brackets
If the name of a member contains square brackets, you must use an escape character, which is also square brackets []
if an identifier consists of multiple parts of the name composition, the MDX uses dots to separate

#########Basic MDX Queries

The MDX query must contain the following items:
1. The number of axes, up to 128 axes can be specified, but only the first 5 axes have aliases, namely Columns (columns), Rows (rows), Pages (pages), Sections (sections) , Chapters. (ON AXIS(index) index axis number, starting with 0), the axis can be referenced using its ordinal position or alias
in the MDX query 2. Members of each dimension to be included on each axis of the MDX query (axis dimension member)
3. The name of the cube that sets the context of the MDX query
4. The member from the slicer dimension on which to slice (scoped) the member from the axis dimension
5. The tuple is usually enclosed in curly braces {}
    You can use commas and colons to separate the members of a unit collection or use the .Member
    operator to return all members of a dimension, level or hierarchy
    Note: ":" only has one direction. For example, February: October, return February to October; October: February, return October to December
    Note: If the dimension has multiple levels, the definition of the hierarchy should also be included
    when constructing the set Is comma and colon can use
    
########.Member and .Children
at the same time Member
    Note: Computed members are not returned
2. The .Chidren operator returns all child members of the next level of a dimension member at a certain level

########Crossjoin() function joins members of multiple dimensions
In most cases, cells will contain members of multiple dimensions, and MDX uses the CrossJoin() function to achieve this.
Crossjoin({Set1},{Set2})
This function returns the result of the intersection of members of two different sets {Set1}, {Set2}. Intersection, or Cartesian product, refers to all possible combinations of these members.

Note:
1. The order of the sets in the CrossJoin function is irrelevant and will not affect the result, only the order of the first-level and second-level headers of the columns
2. The CrossJoin function can only process two sets at a time. If you want to calculate the cross product of more than two sets, you need to use this function nested.

#########Using the Order() function to sort the data The function of
the Order() function is to sort the collection according to the specific order of the magic clothes. The
parameters are the collection to be sorted, the sorting basis, and an arrangement.
Syntax:    
    Order({SET},Criterion for ordering,Flag(DESC,ASC,BASC,BDESC))

    
########Members and Member Keys
The way to refer to a member is to refer to the member key (&)
? ? ? Member keys are used by dimensions to specifically identify a given member


##########Establishing a cube context
The from clause does not qualify a user using multiple cubes at a time, and the LookupCube function can be used to retrieve data from cubes outside the context of the cube.
Unlike SQL, the From clause does not allow multiple cubes to be joined later.

#########Creating and using property values

1. The decomposition of the DIMENSION PROPERTIES keyword
    property syntax will vary depending on the property being queried. The dimension and level name must be added before the intrinsic member properties of the dimension and level.
    A member's intrinsic member attribute cannot be qualified by a dimension name or level name.
    Custom member properties should be preceded by the name of the level in which they reside.
    
2. Properties function
    ? ? ? Member properties can also be retrieved using the Properties function. The Properties function is a string function, and the Val() function can be used to force member properties into strings.

3. Intrinsic dimension and level member properties
    All dimensions and levels support the following intrinsic member properties.
    ID member's internal maintenance ID
    Key The value of the member stored in the MEMBER_KEY column of the MEMBERS schema rowset
    Name The name of the member
    DIMENSION.PROPERTIES [«Dimension»].«Level».ID The
    
    dimension member property is preceded by the name of the dimension to which the property is applied:
    DIMENSIUON PROPERTIES <DIMENSION>.ID
    
    The level member property can be preceded by the level name.
    DIMENSIUON PROPERTIES <DIMENSION>.<Level>.ID
    
    
4. Intrinsic member properties
    Intrinsic member properties cannot be applied to a specific dimension or level, that is, intrinsic member properties cannot be requested for a specific dimension or level. Instead, it is used for all members of the axis dimension in a multidimensional expression MDX query.
    Specify PROPERTIES DISCRIPTION in an MDX query to return a description of each member of the axis dimension.
    
    CALCULATION_PASS_DEPTH (pass depth of calculation formula): only for calculation unit. Determine how many passes are needed to parse the calculation formula
    
    CALCULATION_PASS_NUMBER: The calculation formula pass number determines on which pass the parse formula will start the assignment and end the calculation. The default value is 1 and the maximum value is 65535.
    
5. Custom Member Properties
    Custom member properties can also be added to a specific named level in a dimension, the "All" level of a dimension that cannot be added, or the dimension itself.
    Reference syntax:
        PROPERTIES [<Dimension>].<Level>.<Custom Member Property>
    
6. Use of
    unit properties MDX unit properties contain information about the content and format of the unit.
    MDX supports the CELL PROPERTIES keyword in the SELECT statement to retrieve intrinsic cell properties.
    Syntax:
    SELECT [axis information]
    FROM [cube]
    WHERE [slice conditions] [cell properties]
    
    <cell properties> Use the CELL PROPERTIES keyword along with one or more intrinsic cell properties.
    Syntax: CELL PROPERTIES <property>
    
    Intrinsic cell properties:
    BACK_COLOR: Background color
    CELL_EVALUATION_LIST: A column of semicolon-separated job search formulas applicable to cells, arranged in order from low to high.
    CELL_OPDINAL: The serial number of the cell in the
    dataset FORE_COLOR: VALUE or foreground color of the FORMATTED_VALUE property
    
    By default, if the CELL PROPERTIES keyword is not used, the cell properties VALUE, FORMATTED_VALUE, CELL_ORDINAL (in order) are returned
    
7. Use the Custom Member Option property
    ? ? ? Cell properties can be set through Analysis Manager using the Custom Member Options property of the Dimension Editor or Cube Editor

#########Format String    
8. Using the FORMAT_STRING cell attribute
    FORMAT_STRING cell attribute is used to format the VALUE cell attribute to create the FORMATTED_VALUE cell attribute value.
    The format string varies depending on the data type of the cell value.
    
9. The format expression of the format string using the string value
    can be one part or two parts separated by a good (;)
    part. When the format is applied to all the two parts of the string value
    , the first part applies applies to string numbers, while the second part applies to nulls and zero-length strings ("")
    @string placeholder, explicit one character plus one space
    & string placeholder, explicit one character or whatever Do not display
    < Force lowercase.
    > Force uppercase
    ! Forces left-to-right padding of placeholders
    
10. Format strings using numeric values ​​A
    user-defined format expression for numbers can have one to four parts separated by semicolons.
    one part: the format expression is applied to all values
    ​​two parts: the first part is applied to positive and zero values, the second part is applied to negative values
    ​​three parts: the first part is applied to positive values, the second part is applied to negative values, the third part is applied
    Four parts to zero: the first part applies to positive values, the second part applies to negative values, the third part applies to zeros, and the fourth part applies to null values
    
​​11. Generate named sets in MDX
    A named set is a set expression associated with an alias, a collection of dimension members, or a created reusable set expression.
    Use WITH to create a named set
    WITH 
    SET <set_name> AS '<set>'
    <set_name> parameter contains the alias of the named set
    <set> parameter contains the set expression pointed to by the alias of the
    
    named
    set Valid within the scope of
    2. The named set defined by the WITH segment belongs to the part of the query, and is invalid after the query is executed.
    3. You can use CREATE SET to create a collection of servers or clients. The collection created by the server is available to the client who accesses or queries the cube where the collection is located. The
       collection created by the client can only be used in the client using
    
    InStr([start], string1, string2, [compare]): return Specifies the first occurrence of a string within another string
    ???CurrentMember: Denies access to the measure "XX" cell, but allows access to all other measure cells.
    Filter(<Set>,<Search Condition>): Returns the set obtained by filtering the specified set according to the search conditions.
    
12.


    WITH 
        MEMBER <member_name> AS '<calculation_formula>'
        [SOLVE_ORDER=<unsigned integer>]optional
        [<cell_property>=<value_expression>]optional
        
        <member_name>value is the legal name of the calculated member,
        <calculation_formula>after calculation , will return the value of the calculated member.     Use
        the SOLVE_ORDER keyword to specify the solution order of the calculated member.
        <cell_property> provides the name of the cell property and <value_expression> provides the value of the cell property
        
In the query, MDX also supports defining computed members on the server or client side.
          A server-side calculated member is visible to all clients that can access the cube in which the member resides. The function is the CREATE MEMBER statement
          1. It is used with the name of the cube and the name of the dimension
          2. This statement is not part of the query using members, it is a separate statement

13. Generated calculated members of MDX
    Calculated members can be created anywhere in the hierarchy.
    Computed members in the same MDX can be referenced by other computed members.
    
14. Use functions in computed members
    Arithmetic operators: +, -, *, /
    Comparison operators: <,>,>=,<=,<> ??? ,=
    Bitwise operators: AND, OR, NOT , XOR ???
    Set operator: <Set1>+<Set2> performs the Union function on the two sets;
                <Set1>*<Set2> performs the CrossJoin function on the two sets; ???
                <Set1>-<Set2> pairs The two sets execute the Except function;
                <Member1>:<Member2> creates a naturally ordered set with two members as endpoints, and all distances between the two specified members are included as members of the set.

15. Numerical functions
    ??? Aggregate function Aggregate()
    The Median function calculates the median value within a set.
    sum()

16. String Function
    MemberToStr
    
17. Collection Functions
    Collection functions are used to return collections in MDX, providing users with the ability to generate dynamically defined collections and quickly create reusable named collections.
    Members function: Returns multiple members (except calculated members) of a level or dimension as a set.
    
18. The tuple function is
    used to return a tuple
    StrToTuple in MDX
    
19. Member functions
    are often referenced in members of calculated members, and member functions allow calculated members to perform complex member retrievals to easily handle hierarchies and collections
    
20. IIF function IIF
    in MDX Function can be used to perform a simple yes or no decision
    IIF(expression, 'YES', 'NO')

21. Generate cache in    
    MDX MDX commonly used cube slices are loaded into memory and cached for faster retrieval.
    (1) The CREATE CACHE statement can be used
    (2) The WITH statement can be used
    
    WITH CACHE AS '(<Set>)'
    <Set> is a set expression used to create a cache, the rules are as follows:
    each <set> must contain only A member from a dimension. Each member must be different from each other Each <Set> must come from     a
    different dimension <Set> cannot contain
    measure values each unit within.     Created using the CREATE CELL CALCULATION statement.     For an existing dataset, the ALTER CUBE statement can be used to add compute units.     WITH CELL CALCULATION <formula_name> FOR '(<calculation_subcube>)' AS '<calculation_formula>'     <formula_name> is the name of the calculation unit.     <calculation_subcube> contains a list of orthogonal, one-dimensional MDX set expressions, each of which must resolve to one of the following set categories:     1. Empty Collection: In this case the collection is ignored.     2. Single member set: resolves to a single member set expression
    




    





    3. Set of level members:
    4. Set of descendants: ? ? ?
    
23. Use user-defined functions in MDX to
    call without parameters:
    MyNewFunction()
    is called with parameters:
    MyNewFunctionWithParms("Parameter1",2,800)
    
24. USE LIBRARY statement
    Use the USE LIBRARY statement to perform loading of external libraries. User-defined functions must be associated with COM classes, which are usually provided in the form of Microsoft ActiveX Dynamic Link Libraries (DLLs)
    ***The USE LIBRARY statement without parameters will unregister all function libraries***
    
25. Drop LIBARARY The statement is
    used to unload a specific or all library
    DROP LIBRARY "library name"
    
26. Create user-defined functions
    User-defined functions can be created in any programming language that supports the COM interface to
    accept any castable string, number or string array or Array of parameter
    user-defined type or object reference cannot be used as parameter
    Array can be used as parameter
    
27. Use writeback? ? ? ? ? ?
    Write-Enable Cube Features for Writing Information into MDX
    1. Lowest-level member write-back
    refers to the member in a dimension that is associated with the lowest defined level of that dimension.
    2. Member writeback at the aggregate level
    The value of the aggregation level member depends on the value of the member associated with the level below the aggregation level.
    
28. Retrieving data source using DRILLTHROUGH? ? ? ? ? ?
    The DRILLTHROUGH statement retrieves sets of rows from the source data. (Earn)
    can use AllowDrillTHrough and DrillthroughColumns properties
    DRILLTHROUGH [MAXROWS <positive number>] [FIRSTROWSET <positive number>]

    
29. Comments in MDX
    // C++ style
    -- SQL style
    /*..*/ C style
    comments add information without affecting performance

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325261593&siteId=291194637