BI Tools

Tips and tricks for building information maps, OLAP cubes, reports, and dashboards

BI Admin

Learn your way around a SAS BI installation.

Visual Analytics

Learn your way around the SAS Visual Analytics tool

Coding & Data

Extract, transform, and load your data into the SAS BI toolset

Stored Processes

Create and design stored processes like a rock star

Home » BI Tools

SAS OLAP Cubes: Percent of Total MDX Calculation

Submitted by on 2011-12-06 – 7:00 AM

MDX is a powerful tool for building custom calculations in SAS OLAP cubes.  Here is a good example of computing the percent of total for a given measure and given hierarchy in a dimension.  This code is written as part of the PROC OLAP procedure.

DEFINE Member “[SGF].[Measures].[Percent of Total Sales]” AS


  [Product].[Product].CurrentMember, [Measures].[SalesSum])/


       , [Measures].[SalesSum]) = 0

  OR   ([Product].[Product].CurrentMember.Parent

       , [Measures].[SalesSum]) = NULL

       , ([Product].[Product].CurrentMember

       , [Measures].[SalesSum])

       , ([Product].[Product].CurrentMember.Parent

      , [Measures].[SalesSum])


The important thing to realize here is that this MDX code is specific to a hierarchy.  I have made the hierarchy references bold in the example above to show this.  I will go into how to make this part of the code dynamic in a future post.  This MDX calculation does basic division to compute a percentage by using the “CurrentMember” and “Parent” MDX functions to dynamically reference aggregations at the parent or “total” level for a given measure.

Here is the example output:

SAS BI OLAP Cube MDX Calculation Examples

SAS BI OLAP Cube MDX Calculation Examples

Example code and data can be found here:

Bryan Stines and I wrote a paper for SAS Global Forum 2011 called  Measures, Members, and Sets, Oh My! Advanced OLAP Techniques, which also describes this technique.

Learn all about SAS BI

You can learn more about SAS Business Intelligence from the "SAS BI Bible." Take a peek inside the Building Business Intelligience with SAS book.

The following two tabs change content below.
Spread the love