SQL Server Analysis Services

MSDN Documentation | Analysis Services | OLAP Modeling

Measure Design in SQL Server Analysis Services

Measures are the numerical values that users analyze in a cube. They represent quantifiable business metrics such as sales amount, quantity sold, or employee count. Effective measure design is crucial for creating a cube that provides meaningful insights and supports business analysis.

Understanding Measures

Measures are typically derived from fact tables in a relational data warehouse. They are aggregated values that can be sliced and diced by dimensions. In Analysis Services, measures are created from columns in the data source or can be calculated using MDX (Multidimensional Expressions).

Types of Measures

Measures in Analysis Services can be categorized into several types:

Designing Effective Measures

When designing measures, consider the following best practices:

1. Clarity and Understandability

Measure names should be intuitive and clearly reflect the data they represent. Avoid ambiguous abbreviations.

2. Granularity

Measures should be designed at the lowest possible grain that makes sense for analysis. This allows for flexible aggregation and avoids data loss.

3. Aggregation Behavior

Define appropriate aggregation functions (Sum, Average, Count, etc.) for each measure. Understand how different aggregations will affect the results when sliced by various dimensions.

For example, averaging a SalesAmount per transaction might be meaningful, but averaging a Quantity might not be useful if the number of transactions varies greatly.

4. Calculation Logic

For calculated measures, ensure the MDX logic is correct, efficient, and adheres to business rules. Test calculated measures thoroughly with different dimensional contexts.

Note: The default aggregation for numeric columns is usually SUM. Ensure this is the desired behavior for your measures.

5. Redundant Measures

Avoid creating multiple measures that represent the same underlying data or calculation. Consolidate where possible to simplify the cube structure and reduce maintenance overhead.

Creating Measures in SQL Server Data Tools (SSDT)

Measures are typically created within the Cube Designer in SSDT:

  1. Navigate to the Measures pane in the Cube Designer.
  2. Click the New Measure button or right-click in the pane.
  3. Specify the Data Source View and the source column or MDX expression.
  4. Define the Name, Source, and Aggregation Function.
  5. For calculated measures, enter the MDX expression in the formula editor.
  6. Configure additional properties such as Format String, IsAggregatable, and Display Folder.

MDX for Calculated Measures

MDX is used to define complex calculations. Here are some common patterns:

Example: Year-over-Year Sales Growth


IIF(
    IsEmpty(
        [Measures].[Sales Amount]
    ) OR
    IsEmpty(
        [Measures].[Sales Amount].PrevMember
    ),
    NULL,
    (
        [Measures].[Sales Amount] - [Measures].[Sales Amount].PrevMember
    ) / [Measures].[Sales Amount].PrevMember
)
            

Example: Sales Amount by Product Category


SUM(
    Existing([Dim Product].[Category].[Category].Members),
    [Measures].[Sales Amount]
)
            
Tip: Use the MDX Script Editor in SSDT to write and test your MDX formulas. Leverage IntelliSense for assistance.

Measure Formatting

Proper formatting of measures significantly enhances user experience. Use the Format String property to define how numbers are displayed (e.g., currency, percentages, thousands separators).

Common format strings include:

Measure Groups

In tabular models, measures are associated with tables. In multidimensional models, measures are organized into Measure Groups. Measure groups help manage the physical storage and performance of measures, often corresponding to fact tables.

Best Practices Summary

Important: Thorough testing of all measures, especially calculated ones, with various combinations of dimensions is critical to ensure data accuracy and integrity.