Microsoft SQL Server Documentation

Designing Measure Groups

This document provides a comprehensive guide to designing and implementing measure groups within SQL Server Analysis Services (SSAS) multidimensional models. Measure groups are fundamental components of a cube, representing collections of measures that share common data sources and aggregation properties.

What are Measure Groups?

A measure group is a collection of related measures, typically derived from one or more tables in a relational data source. In SSAS, a measure group is built on top of a fact table (or multiple fact tables in certain scenarios). All measures within a single measure group must belong to the same aggregation granularity, meaning they are aggregated to the same level of detail.

Key Characteristics of Measure Groups:

  • Data Source: Defined by a source table or view in your data source.
  • Aggregation Granularity: All measures within the group share the same lowest level of detail.
  • Measures: Contains one or more measures (e.g., Sales Amount, Quantity, Cost).
  • Partitions: Can be divided into partitions for performance optimization and data management.
  • Storage Mode: Determines how data is stored (MOLAP, ROLAP, HOLAP).

Creating a Measure Group

Measure groups are typically created using SQL Server Data Tools (SSDT) or SQL Server Management Studio (SSMS). When you add a fact table to a cube, SSDT automatically creates a corresponding measure group.

Steps to Create a Measure Group (using SSDT):

  1. Open your SSAS project in SSDT.
  2. Navigate to the Solution Explorer and double-click on the cube where you want to add the measure group.
  3. In the Cube Designer, go to the "Data Source View" pane.
  4. Drag the fact table (or tables) that contain your measures onto the cube structure. SSDT will prompt you to create a new measure group.
  5. Configure the measure group properties, including the source table, name, and aggregation setting.
  6. Define the measures that will reside in this measure group.
Tip: It's a best practice to group measures that share the same fact table and aggregation level into a single measure group. This simplifies management and can improve performance.

Measure Group Properties

Each measure group has several important properties that you can configure to optimize performance, manage data, and define behavior.

Key Properties:

  • Name: A unique identifier for the measure group.
  • Table/View: The underlying table or view in the data source.
  • Database: The database containing the source table.
  • Schema: The schema of the source table.
  • Aggregation Mode: Determines how aggregations are created and stored (e.g., `Full`, `None`, `FastPartial`, `Hybrid`).
  • Storage Mode: Defines how the measure group data and aggregations are stored (`MOLAP`, `ROLAP`, `HOLAP`).
  • Proactive Caching: Enables caching of aggregations to improve query performance.
  • Timestamp Column: Used for incremental processing.
-- Example of setting storage mode programmatically (MDX DDL)
ALTER CUBE [YourCube]
MODIFY MEASUREGROUP [YourMeasureGroup]
WITH STORAGE_MODE = MOLAP;

Storage Modes

The storage mode significantly impacts query performance, data refresh times, and server resource utilization.

  • MOLAP (Multidimensional Online Analytical Processing): Data and aggregations are stored in the Analysis Services database. Offers the best query performance but requires more processing time for data refreshes.
  • ROLAP (Relational Online Analytical Processing): Data remains in the relational source database, and aggregations are performed dynamically when queries are executed. Offers faster data refreshes but slower query performance.
  • HOLAP (Hybrid Online Analytical Processing): A combination of MOLAP and ROLAP. Dimension data and aggregations are stored in Analysis Services (MOLAP), while fact data is stored in the relational source database (ROLAP). Offers a balance between performance and data refresh speed.
Important: The choice of storage mode depends on your specific requirements for query speed, data freshness, and available resources.

Partitions

Partitions allow you to divide a measure group into smaller, manageable segments. This is crucial for performance tuning, data management, and incremental processing.

Benefits of Partitioning:

  • Performance: Queries can be directed to specific partitions, reducing the amount of data scanned.
  • Data Management: Easier to load, update, or delete data for specific periods or segments.
  • Incremental Processing: Allows only recently changed data to be processed, saving time and resources.

Partitioning Strategies:

  • Time-Based: The most common strategy, partitioning data by year, quarter, or month.
  • Geographic: Partitioning by region or country.
  • Business Unit: Partitioning by department or product line.

Partitions are configured within the "Partitions" tab of the Cube Designer.

Aggregation Design

Analysis Services can automatically create aggregations to speed up query processing. Measure groups provide settings to control how these aggregations are designed and managed.

Aggregation Options:

  • Aggregation Design Wizard: A tool in SSDT to help you create optimal aggregations.
  • Aggregation Cache: Storing frequently used aggregations in memory.
  • Aggregation Usage: You can specify which dimensions and hierarchies should be included in aggregations for a measure group.
Note: While automatic aggregations can improve performance, over-aggregation can lead to excessive storage space and longer processing times. Carefully analyze your query patterns to design effective aggregations.

Best Practices for Designing Measure Groups

  • Logical Grouping: Group measures that originate from the same fact table and share the same granularity.
  • Descriptive Naming: Use clear and descriptive names for measure groups.
  • Appropriate Storage Mode: Select the storage mode that best fits your performance and data refresh needs.
  • Effective Partitioning: Implement partitioning based on your data's characteristics, typically by time.
  • Controlled Aggregation: Design aggregations judiciously to balance performance gains with storage and processing overhead.
  • Data Source View Design: Ensure your Data Source View is well-designed, with appropriate joins and naming conventions, as it directly impacts measure group creation.