Search code examples
ssas

Programatically create Relationship to Fact Dimension


I want to create a "Fact" type relationship between a Measure group and a "Fact dimension" both based on the same fact table.

I use the below piece of code

var cubeDim = OlapCube.Dimensions.GetByName(dimensionName);
var regMgDim = new RegularMeasureGroupDimension(cubeDim.ID);
olapMeasureGroup.Dimensions.Add(regMgDim);

var cubeDimKeyAttr = cubeDim.Dimension.KeyAttribute;
var mgAttr = regMgDim.Attributes.Add(cubeDimKeyAttr.ID);
mgAttr.Type = MeasureGroupAttributeType.Granularity;

But it gets created as a "Regular" type relationship.

I want it to end up like this (See relationship type):

enter image description here


Solution

  • Managed to figure it out.

    The code should be,

    var cubeDim = OlapCube.Dimensions.GetByName(dimensionName);
    var regMgDim = new DegenerateMeasureGroupDimension(cubeDim.ID);
    olapMeasureGroup.Dimensions.Add(regMgDim);
    

    Although the name DegenerateMeasureGroupDimension is not obvious, it is the dimension to create fact dimension relationship.