IMatrixFactory.CreateQuery

Syntax

CreateQuery(Value: IMatrix): IMatrixQuery;

Parameters

Value. Matrix, for which a query is created.

Description

The CreateQuery method creates a query that is used to get information about existing data in the specified matrix.

Example

Executing the example requires a cube with the CUBE identifier.

Add links to the Cubes, Dimensions, Matrix, Metabase system assemblies.

Sub UserProc;
Var
    Mb: IMetabase;
    CubeDest: ICubeInstanceDestination;
    Executor: ICubeInstanceDestinationExecutor;
    Sels, ResSels: IDimSelectionSet;
    Sel: IDimSelection;
    Factory: IMatrixFactory;
    Matrix: IMatrix;
    Query: IMatrixQuery;
    Filter: IMatrixQueryFilter;
    Range: IMatrixQueryFilterRange;
    Result: IMatrixQueryResult;
Begin
    Mb := MetabaseClass.Active;
    // Open cube
    CubeDest := (Mb.ItemById("CUBE").Open(NullAs ICubeInstance).Destinations.DefaultDestination;
    Executor := CubeDest.CreateExecutor;
    // Create selection
    Sels := CubeDest.CreateDimSelectionSet;
    For Each Sel In Sels Do
        Sel.SelectAll;
    End For;
    // Get matrix with cube data
    Executor.PrepareExecute(Sels);
    Executor.PerformExecuteO(CubeInstanceDestinationExecutorOptions.Cached);
    Matrix := Executor.Matrix;
    // Create a query
    Factory := New MatrixFactory.Create As IMatrixFactory;
    Query := Factory.CreateQuery(Matrix);
    Filter := Query.Filter;
    // Add a data filtering range
    Range := Filter.Ranges.Add;
    Range.Min := 1;
    Range.Max := 10;
    // Selection for filtering
    Filter.Selection := Sels;
    // Execute query
    Query.Execute;
    Result := Query.Result;
    Debug.WriteLine("Minimum value in filtered matrix: " + Result.MinValue.ToString);
    Debug.WriteLine("Maximum value in filtered matrix: " + Result.MaxValue.ToString);
    // Output selection obtained by changing source selection so that
    // the matrix contains only data from filter
    ResSels := CubeDest.CreateDimSelectionSet;
    Result.GetSelectionSet(ResSels);
    For Each Sel In ResSels Do
        Debug.WriteLine("Dimension: " + (Sel.Dimension.Dimension As IMetabaseObject).Id + ". Selected elements: " + Sel.SelectedCount.ToString + " of " + Sel.Dimension.Elements.Count.ToString);
    End For;
End Sub UserProc;

After executing the example the cube opens and its matrix with data by full selection is obtained. A query will be created that gets information about matrix data, a filter that selected data in from the specified range is determined in the query. After executing the query the selection corresponding to the matrix with filtered data is obtained. Information about the selection is displayed in the development environment console.

See also:

IMatrixFactory