Technical Training
Analysis Services TrainingTable of Contents
MSAS - Implementing Calculations Using MDX Part 2
MSAS - Implementing Calculations Using MDX Part 2 - Page 2
MSAS - Implementing Calculations Using MDX Part 2 - Page 3
MSAS - Implementing Calculations Using MDX Part 2 - Page 4MSAS - Implementing Calculations Using MDX Part 2 Page - 2
MSAS - Implementing Calculations Using MDX Part 2
Using Functions in Calculated Members
Multidimensional Expressions provide a lot of flexibility to calculated members. The variety of intrinsic functions available for use in MDX, the variety of functions built into the MSSQL 2000 Analysis services function Libraries and the capability of including and registering external libraries, all add to the flexibility of Calculated members. The variety of functions available and the study of them would require a separate tutorial series on its own. Hence only the commonly used functions are highlighted in this series.
A variety of arithmetic, logical and comparison operators are supported by MDX expressions. The Arithmetic operators include +(Addition),-(Subtraction),*(Multiplication) and /(Division). Comparison operators include <(Less than),>(greater than), <=(Less than and equal to), >=(greater than and equal to), <>(Not equal to) and =(equal to). Comparison operators compare the two strings, numeric expressions or date expressions and return a True or False. Null values are treated as zero when compared with a non null value. Null values can be checked using the function IsEmpty or Is function to return a true or false. Bitwise operators return True or False based on logical expressions. The expressions are evaluated against logical values. Numeric values are converted implicitly into logical values before a logical comparison is made. Numerical expressions that evaluate to 0 or Null are considered false, else True. String expressions are not implicitly converted and usage of string expressions with bitwise operators results in errors. Bitwise operators are AND ,OR, NOT and XOR. Set Operators deal with the creation, separation and joining of sets. They use + (Union), * (CrossJoin), - (Except) and : (naturally ordered set with the members as endpoints).
There are a variety of functions used in MDX expressions. Let us look at these functions on basis of the category of data they return. The first of these is the Numeric Function. Numeric functions are used to perform a variety of aggregations and statistical calculations. MDX Aggregate functions are used to quickly perform calculations across a number of members. These members are specified as a set. The aggregate function becomes powerful when combined with a measure that produces a sum. For instance let us assume that a query has to be built for producing a sum of the store sales for each state. The aggregated values for the first and second half of the year are to be supplied by the calculated members using aggregate functions. The difference between the two supplied by a third member. The structure of the MDX would be as under:
WITH
MEMBER[Time].[1ST Half Sales] AS ‘Aggregate{{Time.[Q1], Time.[Q2]}}’
MEMBER[Time].[2nd Half Sales] AS ‘Aggregate{{Time.[Q3], Time.[Q4]}}’,
MEMBER [Time].[Difference] AS ‘Time.[2nd Half Sales]- Time.[1st Half Sales]’,
SELECT
([Store].[Store State].Members) ON COLUMNS,
{Time.[1st Half Sales], Time.[2nd Half Sales], Time.Difference} ON ROWS
FROM Sales
WHERE [Measures].[Store Sales]
MDX also provides the user with a large number of statistical calculations. For instance statistical covariance and standard deviation can be calculated using the MDX functions. Other numerical functions are the Sum(), Count(), Avg().
String functions supplied by MDX not only process strings but also support user defined functions. For instance MemberToStr function converts a member reference to a string in the MDX format for use in user defined functions. It must be noted that user defined functions cannot accept object references from MDX.
Set Functions provide the user with the capacity to easily build dynamic sets and quickly create reusable named sets. For instance the commonly used set function --Members function-- returns all the members of the set other than calculated members of a level. The structure of the function is as under:
SELECT
NON EMPTY { [Store].[Store Name].Members} ON COLUMNS,
{Measures.[Store Sales]} ON ROWS
FROM Sales
The above example returns total store sales figures for each store in the Sales cube.
Tuple Functions are used to return tuples. These functions aid user defined functions in MDX. As user defined functions cannot handle MDX object references, it must pass back a string return value in MDX format representing a tuple and then use the StrToTuple function to convert it to a valid tuple reference.
Member Functions allow calculated members to perform complex member retrieval. Hierarchies and sets are negotiated with ease.
Calculated members can be constructed based on iterations over the members of a set. Hence the resolution of calculated members can be iterative in nature. The CurrentMember function allows the user take advantage of this feature.
MDX provides users with other Functions that deal with dimensions, hierarchies, levels and arrays. Examples of such functions are SetToArray function which allows user defined functions to receive set references as a variant array of individual members represented as strings. This further permits user defined functions to supply set related functionality.
Time series functions provide a variety of capabilities critical to advanced data analysis and decision support systems. YTD(),QTD(),MTD() and WTD() functions are some of the time series functions commonly used.
Time series Analysis functions for performing simple linear regression analysis using the least squares method. Examples of these functions are LinRegIntercept() function, Covariance() function, Correlation() function and so on.
Miscellaneous MDX functions such as the Generate() function, the Parent() function, Decendants() function etc are also extremely useful in building MDX queries and expressions.
Analysis Services Training
- MSAS - Browsing the Dependency Network
- MSAS - Building a Relational Decision Tree Model
- MSAS - Introduction to Data Mining
- MSAS - Applying security to a Dimension
- Tutorial 65: MSAS - Managing Cube Roles
- MSAS - Understanding Database Roles
- MSAS - Securing User Authentication
- MSAS - Introducing Analysis Services Security
- MSAS - Writebacks
- MSAS - Defining and Creating Drillthrough
- MSAS - Defining and Creating Auctions
- MSAS - Creating and Maintaining Calculated Members in Virtual Cubes
- MSAS - Building a Virtual Cube
- MSAS - Understanding Virtual Cubes
- MSAS - Introducing Solve Order
- MSAS - Implementing Calculations Using MDX Part 2
- MSAS - Implementing Calculations Using MDX Part 1
- MSAS - Merging Partitions
- MSAS - Introduction and Managing Partitions
- MSAS - Troubleshooting Cube Processing
- MSAS - Optimizing Cube Processing
- MSAS - Processing Dimensions and Cubes
- MSAS - Introducing Dimension and Cube Processing
- MSAS: Optimization Tuning Part 2
- MSAS: Optimization Tuning Part 1
- MSAS: Usage-Based Optimization
- MSAS: Analysis Services Aggregations
- MSAS: The Storage Design Wizard
- MSAS: Analysis Server Cube Storage
- MSAS: Defining Cube Properties
- MSAS: Introduction and Working with Measures
- MSAS: Introduction and Working with Cubes
- MSAS: Virtual Dimensions
- MSAS: Introducing Member Properties
- MSAS: Creating Custom Rollups
- MSAS: Creating a Time Dimension
- MSAS: Understanding Hierarchies
- MSAS: Dimension Storage Modes and Levels
- MSAS: Working with Levels and Hierarchies
- MSAS: Working with Parent-Child Dimensions
- MSAS : Basics of Levels
- MSAS : Working with Standard Dimensions
- MSAS : Shared vs Private Dimensions
- Understanding Dimension Basics
- MSAS : Office 2000 OLAP Components
- MSAS : Client Architecture
- MSAS : Cube Storage options
- MSAS : Meta data Repository
- MSAS : Analysis services Tools for Extended Functionality
- MSAS : The Wizards
- MSAS : The Analysis Manager and Analysis Server
- MSAS : The Data warehousing framework of SQL Server 2000 - Part 2
- MSAS : The Data warehousing framework of SQL Server 2000 - Part 1
- MSAS : Microsoft Data Warehousing Overview
- MSAS : Browsing the Cube
- MSAS : Designing Storage and Processing the Cube
- MSAS : Building the Cube Part #3
- MSAS : Building the Cube Part #2
- MSAS : Building the Cube Part #1
- MSAS : Setting up the Database in Analysis Server
- MSAS : Preparing to Create the Cube
- MSAS : Introducing Analysis Manager Wizards
- Microsoft Analysis Services Installation
- MSAS - Applying OLAP Cubes
- Understanding OLAP Models
- Designing the Dimensional Model and Preparing the data for OLAP
- Design of the data warehouse: Kimball Vs Inmon
- Defining OLAP Solutions and Data Warehouse design
- Microsoft Analysis Services Training
- Data Warehouse database and OLTP database
- Introduction to Data Warehousing







