SQL Server Analysis Services Documentation

Data Modeling - Measures and Aggregations

Measures and Aggregations in SQL Server Analysis Services

Measures are fundamental to OLAP (Online Analytical Processing) cubes in SQL Server Analysis Services (SSAS). They represent the numerical data that users analyze, such as sales revenue, units sold, or profit margins. Aggregations are the functions used to combine these measures across various dimensions.

Understanding Measures

A measure is typically a column from a fact table in your data source that contains quantitative data. In SSAS, you define measures to enable users to perform calculations and gain insights. Key aspects of measures include:

Aggregation Functions

When a user views data at a higher level of a dimension (e.g., viewing total sales by year instead of by month), SSAS needs to aggregate the measure values. Common aggregation functions used in SSAS include:

The aggregation behavior for a measure is defined in the cube definition and can be configured to optimize performance and ensure correct results. You can specify a default aggregation function, and also define custom aggregations for specific scenarios.

Defining Measures in SSAS

When creating a cube in SSAS, you typically drag and drop measure group columns into the Measures pane. For each measure, you can specify:

Tip: For measures that represent counts (like distinct customers), ensure you use the appropriate aggregation function like `DISTINCTCOUNT` for accurate reporting.

MDX and DAX for Measures

Complex calculations often require MDX or DAX. For example, to calculate a profit margin measure, you might use an MDX expression like:

CREATE MEMBER CURRENTCUBE.[Measures].[Profit Margin] AS
( [Measures].[Sales Amount] - [Measures].[Cost Amount] ) / [Measures].[Sales Amount],
FORMAT_STRING = "Percent",
CAPTION = "Profit Margin"

Understanding how to leverage these languages is crucial for creating sophisticated analytical models.

Performance Considerations

The way measures are aggregated significantly impacts query performance. SSAS uses pre-aggregated data in its storage engine (ROLAP, MOLAP, HOLAP) to speed up queries. Properly defining aggregation designs for your measures is a critical step in performance tuning.

Key Takeaways