Ova

How do you create a hierarchy in Visual Studio tabular model?

Published in Tabular Model Hierarchy 4 mins read

Creating a hierarchy in a Visual Studio tabular model involves organizing related columns into a navigable structure that enhances user experience and simplifies data analysis in client reporting tools.

Understanding Hierarchies in Tabular Models

Hierarchies are crucial for simplifying navigation and improving the usability of your data model. They allow end-users to drill down into data from a high level of aggregation to more granular details, making it intuitive to explore complex datasets. For instance, a common hierarchy might include "Year," "Quarter," "Month," and "Day" for date dimensions, or "Category," "Subcategory," and "Product" for product dimensions.

Why use hierarchies?

  • Improved User Experience: Provides an intuitive way for users to explore data in reporting tools like Power BI, Excel, or SQL Server Reporting Services.
  • Enhanced Navigation: Groups related attributes, making it easier to find and use relevant data points.
  • Consistent Analysis: Ensures that data is analyzed consistently across different levels of detail.
  • Reduced Complexity: Simplifies the list of available fields in client tools by grouping detailed columns under a single hierarchy.

Step-by-Step Guide to Creating a Hierarchy

Creating a hierarchy in a Visual Studio tabular model is a straightforward process performed within the Model Designer.

  1. Open the Model Designer (Diagram View):
    Navigate to the table where you want to create the hierarchy. The Model Designer typically opens in Diagram View, which provides a visual representation of your tables and columns.

  2. Select Columns for the Hierarchy:

    • Single Column: To create a hierarchy starting with a single column, right-click on that specific column within the table window.
    • Multiple Columns: To create a hierarchy from multiple columns, click each column while holding down the Ctrl key to select them. After selecting all desired columns, right-click on any of the selected columns to open the context menu.
  3. Choose "Create Hierarchy":
    From the context menu, select the option "Create Hierarchy". This action will create a new hierarchy object in the table with the selected columns as its initial members.

  4. Name the Hierarchy:
    A new hierarchy object will appear in the table window. Type a descriptive name for your hierarchy. A good name clearly indicates the hierarchy's purpose, such as "Product Category Hierarchy" or "Date Hierarchy."

  5. Rearrange and Add/Remove Columns (Optional):
    After creation, you can further refine your hierarchy:

    • Reorder Columns: Drag and drop columns within the hierarchy to adjust their order (e.g., ensure "Year" comes before "Quarter").
    • Add More Columns: Drag other columns from the same table directly into the hierarchy.
    • Remove Columns: Right-click a column within the hierarchy and select "Remove from Hierarchy" if it's no longer needed.

Best Practices for Designing Hierarchies

Effective hierarchy design significantly impacts the usability and performance of your tabular model.

  • Logical Flow: Ensure the hierarchy follows a natural, logical progression from the highest level of aggregation to the most granular level (e.g., Year -> Quarter -> Month -> Day).
  • Descriptive Naming: Use clear and concise names for both the hierarchy itself and its individual levels.
  • Avoid Redundancy: Only include columns that add value to the hierarchy. Avoid duplicating information unnecessarily.
  • Maintain Consistency: Apply consistent hierarchy structures across similar dimensions (e.g., all date dimensions should have similar date hierarchies).
  • Focus on User Needs: Design hierarchies based on how your end-users will typically explore and analyze data. Consider common reporting patterns.
  • Performance Considerations: While hierarchies generally improve user experience, excessively deep or complex hierarchies might slightly impact processing time for very large models. However, for most use cases, the benefits far outweigh any minor performance considerations.

Example: Creating a Date Hierarchy

Let's illustrate with a common date hierarchy in a DimDate table:

  1. In the Visual Studio Model Designer, open the DimDate table.
  2. Select the CalendarYear, CalendarQuarter, MonthName, and DayOfMonth columns by holding Ctrl and clicking each.
  3. Right-click on any of the selected columns and choose "Create Hierarchy".
  4. Rename the new hierarchy to "Date Calendar Hierarchy".
  5. Verify the order: CalendarYear, CalendarQuarter, MonthName, DayOfMonth. If needed, drag them into the correct sequence.

This hierarchy will then be available in client tools, allowing users to easily drill down from the year level to individual days.

For more detailed information on tabular model development, you can refer to the official Microsoft Learn documentation for SQL Server Analysis Services Tabular Models.