Using alternate hierarchies

Application Engine supports alternate hierarchies in model definition, data insertion and data retrieval.

Multiple hierarchies in a dimension can be used to provide different views to the users. For example, there could be one view on the organization structure as of the last year, a different one for this year and multiple ones for the next years. The base values in this case remain the same, but there might be different aggregated members. Moreover, the calculation of the aggregated members can differ in different hierarchies. Before calculation time, the user or the person preparing the report decides which hierarchy of a dimension will be used.

Application Engine offers OLAP functions to create new dimensions with alternate hierarchies or to add additional hierarchies to existing dimensions. Element insertion functions allow adding elements to, or removing elements from, alternate hierarchies. Element retrieval functions allow reading elements from alternate hierarchies of dimensions.

If you are using OLAPIsBaseElement and the referenced element is not in the default hierarchy, then you could use OLAPCreateCompositeName to create a composite element, which includes both the name of the element and the hierarchy it belongs to. You can then pass the composite element to functions such as OLAPIsBaseElement.

The runtime functions use the parameter withHierarchies that indicates if alternate hierarchies are used. Setting this parameter informs the OLAP that composite element names are used. A composite name is the name of an element that is prepended with the element's hierarchy name. The hierarchy name is separated by the tab character: Hierarchy\tElement, or by the backslash character: Hierarchy\Element.

To create a composite element name, you must use the OLAPCreateCompositeName function.

These are some code examples that use alternate hierarchies:

Cell write:

StringArray els1 = CreateStringArray();
Append(els1, OLAPCreateCompositeName("MHD1_H2", "MHD1_H2_El2"));
Append(els1, "MHD2_H1_El2");
Append(els1, OLAPCreateCompositeName("MHD3_H2", "MHD3_H2_El2"));
      
OLAPCellWriteNumberDynamic(conn, "Cube1", true, 1024, els1);
double v = OLAPCellReadNumberDynamic(conn, "Cube1", 1, els1);
WriteLine(v);
      
StringArray els2 = CreateStringArray();
Append(els2, "MHD1_H1_El2");
Append(els2, "MHD2_H1_El2");
Append(els2, "MHD3_H1_El2");
      
OLAPCellWriteNumberDynamic(conn, "Cube1", 512, els2);
v = OLAPCellReadNumberDynamic(conn, "Cube1", 1, els2);
WriteLine(v);
// the same effect as in the previous case
OLAPCellWriteNumberDynamic(conn, "Cube1", false, 256, els2);
v = OLAPCellReadNumberDynamic(conn, "Cube1", 1, els2);
WriteLine(v);

Data area iteration:

OLAPDataArea area = OLAPCreateDataArea(conn, "Cube1",
OlapDataAreaSuppressNull | OlapDataAreaWithHierarchies,
OlapDataAreaOperatorNone, 0.0, OlapDataAreaOperatorNone, 0.0,
OlapDataAreaAllCells,
"MHD2_H2\tMHD2_H2_El1",
"MHD3_H2\tMHD3_H2_El2");

string w = "";
foreach(OLAPCell c in area)
{
    w = "";
    string d1 = OLAPCellGetElement(c, "MHD1");
    string d2 = OLAPCellGetElement(c, "MHD2");
    string d3 = OLAPCellGetElement(c, "MHD3");
    double value = c;
    w = w + d1;
    w = w + " ";
    w = w + d2;
    w = w + " ";
    w = w + d3;
    w = w + " = ";
    w = w + value;
    WriteLine(w);
}