Measures in SQL Server Analysis Services

Measures are numerical values that are aggregated from data in a cube. They represent the key business metrics that users will analyze, such as sales amount, quantity sold, or profit margin. In SQL Server Analysis Services (SSAS), measures are fundamental to building a multidimensional model that provides insights into business performance.

Understanding Measures

A measure is typically associated with a fact table column that contains numerical data. SSAS provides a rich set of aggregation functions to define how these numerical values are summarized across different dimensions. Common aggregation functions include:

Beyond basic aggregation, SSAS allows for the creation of Calculated Measures. These measures are not directly derived from a fact table column but are computed using formulas that can involve other measures, attributes, or mathematical operations.

Creating Measures

Measures are typically created within the Cube Designer in SQL Server Data Tools (SSDT) or Visual Studio. You can define measures based on columns from your data source view.

Types of Measures

MDX for Calculated Measures

MDX is the query language used in SSAS for retrieving data from cubes. For calculated measures, you'll write MDX expressions.

Example: Calculating Profit Margin

Consider a cube with [Measures].[Sales Amount] and [Measures].[Cost Amount]. A calculated measure for profit margin could be defined as:


IIF(
    [Measures].[Sales Amount] <> 0,
    ( [Measures].[Sales Amount] - [Measures].[Cost Amount] ) / [Measures].[Sales Amount],
    NULL
)
        

Example: Using a Time Dimension

To calculate Year-over-Year (YoY) sales growth, you might use functions like LAG or PARALLELPERIOD.


// Assuming a [Date] dimension with a [Calendar Year] level
[Measures].[Sales Amount YoY Growth] =
    ( [Measures].[Sales Amount], PARALLELPERIOD([Date].[Calendar Year].CurrentMember, 1) )
    / [Measures].[Sales Amount] - 1
        
Note: When defining calculated measures, ensure your MDX syntax is correct to avoid errors during cube processing or querying.

Measure Groups and Aggregations

Measures are organized into Measure Groups within a cube. Each measure group is typically associated with a specific fact table. SSAS can pre-calculate aggregations for measures to improve query performance. These aggregations can be configured to store summarized data for frequently accessed combinations of dimension members.

Performance Considerations

Tip: Regularly review and optimize your cube's aggregations based on query patterns and performance monitoring.

Further Reading