Using Advanced Features of Compare by Expression Validation Rule

The Compare by Expression validation rules enable the use of series from different time series databases, data from different calendar frequencies and data from different revisions in calculation. A number of features exists:

To execute the example, you will need:

Calculation is set up to the formula:

{RussiaPavel!Argentina|NGDP_D.Q} <> collapse({Argentina|NGDP_D.Q:LastRevision}, MsCollapseType.Average, MsFrequency.Annual)

Where:

It is also necessary to add links to the Metabase, Ms, Dimensions, Rds, Cubes, Forms system assemblies.

Sub UserProc;
Var
    mb: IMetabase;
    filter: IValidationFilter;
    customV: IValidationCustom;
    Transform: IMsFormulaTransform;
    variable: IMsFormulaTransformVariable;
    dimSelection: IDimSelection;
    metaAttribute: IMetaAttribute;
    attrVal: IMsMetaAttributeValue;
    rub: IRubricator;
    BreadcrumbItems: IBreadcrumbItems;
    Slices: IMsFormulaTransformSlices;
Begin
    mb := MetabaseClass.Active;
    // get validation rule by its key
    filter := mb.Item(111).Edit As IValidationFilter;
    customV := filter.Details As IValidationCustom;
    // variable of other database
    Transform := customV.Transform;
    variable := Transform.Inputs.Item(0);
    rub := mb.Item(333).Bind As IRubricator;
    // modify variable data source
    variable.SetStub(rub As IVariableStub);
    // as the data source was modified the variable selection must be readjusted
    // set the first dictionary element, to which the Country attribute refers
    BreadcrumbItems := MetaAttributesBreadcrumb1.Items;
    metaAttribute := (BreadcrumbItems.Item(0As IMetaAttributeBreadcrumbItem).MetaAttribute;
    dimSelection := MetaAttributesBreadcrumb1.GetAttributeValue(metaAttribute);
    Slices := variable.Slices;
    Slices.Item(0).Selection.Item(0).DeselectAll;
    Slices.Item(0).Selection.Item(0).SelectElement(dimSelection.Element(0), False);
    //  set the first dictionary element, to which the Factor attribute refers
    metaAttribute := (BreadcrumbItems.Item(1As IMetaAttributeBreadcrumbItem).MetaAttribute;
    dimSelection := MetaAttributesBreadcrumb1.GetAttributeValue(metaAttribute); 
    Slices.Item(0).Selection.Item(1).DeselectAll;
    Slices.Item(0).Selection.Item(1).SelectElement(dimSelection.Element(0), False);
    //set quarterly frequency
    Slices.Item(0).MetaAttributeValueList.Clear;
    metaAttribute := rub.Facts.Attributes.FindByKind(MetaAttributeKind.CalendarLevel);
    attrVal := Slices.Item(0).MetaAttributeValueList.Add(metaAttribute);
    attrVal.Value := DimCalendarLevel.Quarter;
    // variable with the specified frequency and revision, that belongs to the current database
    rub := variable.VariableStub As IRubricator;
    variable := Transform.Inputs.Item(1);
    Slices.Item(0).MetaAttributeValueList.Clear;
    //set quarterly frequency
    metaAttribute := rub.Facts.Attributes.FindByKind(MetaAttributeKind.CalendarLevel);
    attrVal := Slices.Item(0).MetaAttributeValueList.Add(metaAttribute);
    attrVal.Value := DimCalendarLevel.Quarter;
    //set revision to the last one before the relevant data, thus pass the -1 value
    metaAttribute := rub.Facts.Attributes.FindByKind(MetaAttributeKind.Revision);
    attrVal := Slices.Item(0).MetaAttributeValueList.Add(metaAttribute);
    attrVal.Value := -1;
    // save validation rule
    (filter As IMetabaseObject).Save;
End Sub UserProc;

After executing the example calculation parameters of the Compare by Expression validation rule will be changed.

See also:

Examples

IValidationCustom