Measures in Multidimensional Models

Measures are the numerical values that users analyze in a cube. They represent business metrics such as sales amount, quantity sold, or cost. Measures are typically aggregated from fact tables in a data warehouse. In SQL Server Analysis Services (SSAS) multidimensional models, measures are defined within a measure group, which is associated with a data source view.

Types of Measures

SSAS supports several types of measures:

Measure Groups

Measures are organized into measure groups. A measure group typically corresponds to a fact table in the underlying relational database. Each measure group contains one or more measures. When you design a cube, you can select which measure groups to include.

Creating Measures

Measures are created within a measure group in SQL Server Data Tools (SSDT) or SQL Server Management Studio (SSMS). The process generally involves:

  1. Selecting the source column from the data source view.
  2. Choosing the aggregation type (e.g., Sum, Average).
  3. Defining the measure name, format string, and other properties.
Tip: When creating measures, always consider the business context and how the data will be aggregated. Ensure that the chosen aggregation type aligns with the semantic meaning of the data.

Measure Properties

Measures have various properties that control their behavior and presentation:

Calculated Measures

In addition to basic measures derived directly from source columns, you can create calculated measures. These are measures whose values are computed using Multidimensional Expressions (MDX) formulas. This allows for more complex business logic and analysis, such as year-over-year growth or profit margin calculations.

A common scenario for calculated measures is to derive metrics that are not directly stored in the fact table but can be calculated from existing measures or columns. For example:

SUM( [Measures].[Sales Amount] ) / COUNTROWS( [Fact Internet Sales] )

This MDX expression calculates the average sales amount per transaction.

Note: For complex calculations, it's often beneficial to create them as calculated members within a dimension's hierarchy or as named sets rather than as calculated measures, depending on the scope and usage.

Best Practices

Example: Sales Amount Measure

Consider a sales fact table with a SalesAmount column. A common measure would be the sum of this column:

Measure Name Source Column Aggregation Function Format String
Total Sales [dbo].[FactInternetSales].[SalesAmount] Sum $#,##0.00

This measure, when displayed in a report or analysis tool, would show the total sales amount, aggregated appropriately based on the dimensions selected in the query.

By effectively defining and organizing measures, you provide users with the essential building blocks for insightful data analysis within their multidimensional solutions.