In the previous recipe, we created a three-level dimension with a denormalized table. Let's do it with normalized tables. Product
, Product Subcategory
, and Product Category
all reside in different tables related with referential integrity constraints as clearly described in the database diagram.
Like I said earlier, I always set the mapping method to manual whenever I create a new attribute. That prevents the editor from looking at every column in the database with the same name and add it automatically to the attribute definition. I prefer to have control over which tables are selected and which are not when it comes to generating SQL. You may also have noticed that some tables are bold in the attribute editor and some are not. Bold tables are the primary source for that specific attribute, often referred to as lookup tables .
We will begin this time from the top of the dimension, Product Category
.
Follow these steps:
Product Category
.Product Subcategory
attribute, with ProductSubcategoryKey as ID, set the Mapping method to Manual, and check both DimProduct and DimProductSubcategory, this time the bold one should be the latter.Product Subcategory
and update the schema.The Product Category attribute ID appears in two tables: the column ProductCategoryKey is PK in the DimProductCategory table and FK in the DimProductSubcategory. When we set the DimProductCategory to bold, we specify that the one with the PK is the lookup, that is, the principal source of information for that attribute, where the description comes from. We then select the second table to tell MicroStrategy that those two columns are the same ID.
Whenever the two tables appear in the same SELECT
, they will be joined on ProductCategoryKey.
Likewise, the Product Subcategory and Product attributes are related with ProductSubcategoryKey being it the PK in DimProductSubcategory and the FK in DimProduct.
There is hence a cascading relationship that goes from Product Category to Product passing through Product Subcategory, which is the attribute that relates upward with Product Category and downward with Product.
We need to specify parent/child link only once in either attribute, as the setting will be automatically reflected to the corresponding counterpart.