SQL Server Analysis Services Documentation

Creating Hierarchies

Hierarchies represent the relationships between different levels of detail within a dimension. They allow users to navigate through data from a high-level summary down to granular details, providing a structured way to explore and analyze business information.

Understanding Hierarchy Types

There are two primary types of hierarchies in SQL Server Analysis Services (SSAS) multidimensional modeling:

Creating a User-Defined Hierarchy

User-defined hierarchies are the most common type and are created by combining existing attributes within a dimension. This allows you to define navigation paths that make sense for your business analysis.

Steps to Create a User-Defined Hierarchy:
  1. In SQL Server Data Tools (SSDT) or Visual Studio with Analysis Services projects, open your Analysis Services project.
  2. In the Solution Explorer, double-click the dimension you want to add a hierarchy to.
  3. In the Dimension Designer, switch to the 'Browser' tab.
  4. In the 'Attributes' pane, drag and drop the attributes you want to include in the hierarchy into the 'Hierarchy Levels' pane. Arrange them in the desired order from top level to bottom level.
  5. Right-click on the newly created hierarchy in the 'Hierarchy Levels' pane and select 'Rename'. Give it a meaningful name (e.g., "Geography", "Product Hierarchy").
  6. To create a parent-child hierarchy, you need to designate a parent attribute and a key attribute within the same dimension. This is typically done in the Attribute properties.

Configuring Hierarchy Properties

Once a hierarchy is created, you can configure its properties to control its behavior and appearance in client applications.

Example: Creating a 'Date' Hierarchy

Let's consider a 'Date' dimension with attributes like Year, Quarter, Month, and Day. We can create a hierarchy to allow users to analyze data by Year, then Quarter, then Month, and finally Day.


-- Example T-SQL for dimension creation (conceptual)
CREATE DIMENSION [Date]
AS
(
    [DateKey],
    [Year],
    [Quarter],
    [Month],
    [Day],
    [MonthName]
);

-- In SSAS Dimension Designer for 'Date' dimension:
-- Drag 'Year', 'Quarter', 'Month', 'Day' into Hierarchy Levels pane.
-- Rename the hierarchy to "Date Hierarchy".
            

Benefits of Using Hierarchies

Implementing well-defined hierarchies significantly enhances the usability and analytical power of your SSAS cubes:

Key Concept: A dimension can contain multiple hierarchies. For example, a 'Product' dimension might have a 'Product Category Hierarchy' and a 'Product Model Hierarchy'.

Best Practices