Creating Dimensions
This document guides you through the process of creating dimensions in SQL Server Analysis Services (SSAS) using multidimensional modeling.
Understanding Dimension Types
SSAS supports several types of dimensions, each with specific use cases:
- Standard Dimensions: The most common type, representing business entities like Customers, Products, or Dates.
- Degenerate Dimensions: Dimensions that are created directly from fact table columns, often transaction IDs or order numbers.
- Fact Dimensions: Though not a distinct type, fact table columns can be treated as dimensions in certain scenarios.
- Junk Dimensions: Used to consolidate multiple low-cardinality flag or indicator columns into a single dimension to reduce the number of dimensions in a star schema.
Methods for Creating Dimensions
You can create dimensions in SSAS using two primary methods:
Using SQL Server Data Tools (SSDT)
This is the most common and recommended approach. SSDT provides a visual designer for creating and managing dimensions.
- Open your SSAS project in SQL Server Data Tools.
- In Solution Explorer, right-click the Dimensions folder and select New Dimension.
- The Dimension Wizard will launch. Choose the dimension creation method:
- Create from existing table: Select this to base your dimension on a table in your data source.
- Create from a cube dimension: Use this to create a new dimension based on an existing dimension already used in a cube.
- Create from a snowflake schema: Useful for normalizing dimension data.
- Follow the wizard steps, specifying the source table, columns for the dimension attribute hierarchy, and other settings.
- You will define the primary key, name columns, and potentially configure other properties like aggregation settings and member properties.
Example: Creating a 'Product' Dimension
Imagine you have a DimProduct table in your data warehouse with columns like ProductID, ProductName, Category, and Subcategory.
-- Source Table Example:
-- CREATE TABLE DimProduct (
-- ProductID INT PRIMARY KEY,
-- ProductName VARCHAR(100),
-- Category VARCHAR(50),
-- Subcategory VARCHAR(50)
-- );
Using the Dimension Wizard, you would select DimProduct as the source table. ProductID would typically be the key column. ProductName, Category, and Subcategory would become attributes, allowing you to build hierarchies like "Category -> Subcategory -> Product".
Manually Creating Dimensions
Unbound dimensions are not directly linked to a specific table in the data source. They are useful for creating dimensions that represent logical concepts or data that is not stored in a relational table, such as:
- Time/Date Dimensions: While often generated from date tables, you can create custom date structures.
- Scenario Dimensions: Representing different business scenarios (e.g., Budget, Actuals, Forecast).
- User-Defined Hierarchies: Creating hierarchies that don't directly map to a normalized schema.
To create an unbound dimension:
- In SSDT, right-click the Dimensions folder and select New Dimension.
- In the Dimension Wizard, select Create from existing table, but then choose to specify the source table later or select a dummy table if required by the wizard.
- Alternatively, after creating a basic dimension, you can detach it from its source table (if it was initially bound) and manually add members and attributes.
- You can then manually define attributes and members, or populate them programmatically.
Key Components of a Dimension
- Attributes: Represent the descriptive properties of a dimension. For a 'Customer' dimension, attributes could be 'Customer Name', 'City', 'State', 'Country'.
- Hierarchies: Allow users to navigate data at different levels of granularity. A common example is a 'Geography' hierarchy: Country -> State -> City.
- Key Columns: The unique identifiers for each member of a dimension.
- Member Properties: Additional descriptive information associated with each member that can be exposed for analysis.
Best Practices
Next Steps
Once dimensions are created, you will typically proceed to design and create your cubes and define measures.