Creating Measures in Analysis Services

A Deep Dive into MDX and DAX for Business Intelligence

Measures are the core of any business intelligence solution built with Analysis Services. They represent calculations performed on your data, such as sales amounts, profit margins, or customer counts. This article will guide you through the process of creating measures, covering both MDX (Multidimensional Expressions) and DAX (Data Analysis Expressions).

Understanding Measures

In a multidimensional model, measures are typically stored in a measure group and are numeric values that can be aggregated. In tabular models, measures are defined using DAX and can be more flexible, often referencing existing columns from your tables.

Key Concepts:

Creating Measures in Multidimensional Models (MDX)

When working with a cube in Analysis Services, you'll define measures using MDX. You can create measures directly within the cube designer.

Steps to Create a Simple Measure:

  1. Open your Analysis Services project in SQL Server Data Tools (SSDT).
  2. Navigate to the Cube Designer for the relevant cube.
  3. In the Measures pane, right-click and select New Measure.
  4. In the Measure Editor:
    • Name: Give your measure a descriptive name (e.g., Total Sales).
    • Source: Choose the attribute or column from your data source view that will be the basis of the measure.
    • Aggregation: Select the desired aggregation function (e.g., Sum).
    • Format String: Define how the measure's value will be displayed (e.g., $#,##0.00).
  5. Click OK.

Example MDX Measure (Calculated Measure):

You can also create calculated measures with more complex logic. For instance, to calculate profit margin:

CREATE MEMBER [Measures].[Profit Margin]
AS ([Measures].[Internet Sales Amount] - [Measures].[Internet Sales Cost]) / [Measures].[Internet Sales Amount],
FORMAT_STRING = 'PERCENT0';

Creating Measures in Tabular Models (DAX)

Tabular models leverage DAX for measure creation. Measures in tabular models are defined within tables and are often referred to as "Implicit Measures" when created by simply dragging numeric columns, or "Explicit Measures" when written using DAX formulas.

Steps to Create an Explicit Measure:

  1. Open your Tabular model project in SSDT or Visual Studio with the Analysis Services projects extension.
  2. In the Model designer, select the table where you want to create the measure.
  3. In the Modeling tab, click New Measure.
  4. The formula bar will appear. Enter your DAX formula.

Example DAX Measures:

Total Sales:

Total Sales = SUM( 'Sales'[Sales Amount] )

Average Order Quantity:

Average Order Quantity = AVERAGE( 'Sales'[Order Quantity] )

Sales YTD (Year-to-Date): This demonstrates time intelligence functions.

Sales YTD =
TOTALYTD(
    SUM( 'Sales'[Sales Amount] ),
    'Date'[Date]
)
Tip: When creating measures in tabular models, consider using the Format property in the properties pane to define the number format, currency, and percentage display for your measures.

Best Practices for Measures

Note: The choice between MDX and DAX depends on whether you are working with a multidimensional or tabular model. Both languages are powerful and essential for building robust BI solutions.

Conclusion

Measures are the building blocks of your analytical experience. By mastering the creation and design of effective measures using MDX and DAX, you empower users to gain valuable insights from their data. Experiment with different aggregation types and DAX functions to unlock the full potential of your Analysis Services models.

Published: October 26, 2023
Author: Analysis Services Community Team