Professional > Table scripting > Getting started > Reusing axes
 
Reusing axes
Sample script file: ReusingAxes.mrs
In More on concatenation and nesting we learned how to create tables with complex nesting and concatenation. Sometimes you may want to build a complex “banner” axis containing nested or concatenated variables for use in a set of tables. When you want to do this, you don't have to define the axis again and again for each table. You can simply create the axis once and then reuse it in as many tables as you want.
You create a reusable axis by adding a new axis to the Document.Axes collection. For example, this script concatenates age and gender to form a reusable axis:
Dim Axis

Set Axis = TableDoc.Axes.AddNew("MyBanner")
Axis.Specification = "age + gender"
To add a reusable axis to a table, you precede the axis name with the axis keyword and enclose the axis name in parentheses. For example, the following script uses the “MyBanner” axis as the top axis in three tables:
With TableDoc.Tables
  .AddNew("Entrance", "entrance * axis(MyBanner)")
  .AddNew("Education", "education * axis(MyBanner)")
  .AddNew("Similar", "similar * axis(MyBanner)")
End With
Note In the sample script this section is commented out, so to create these tables you need to remove the initial apostrophe (') from each line of the With statement.
Three tables using the same top axis
Here are the tables produced by the script:
The next example is an advanced example of using the banner in multiple tables without mentioning the variables by name. This means that you can use the script on any data set. The example uses the Table Object Model Document.DataSet.MDMDocument property to access to the metadata in the MDM Document. See Working with metadata for more information.
The script in this example loops through the MDM Document.Variables collection and tests each VariableInstance object to see whether it is a simple categorical variable. If it is, the script creates a table with the variable on the side axis and the reusable axis on the top axis.
Dim MyVariableInstance, MyCounter, MyTableName, MyTableSpec, MyTableDescription

' Set the counter to zero
MyCounter = 0

' Loop through the top-level variable instances
' and create a table using the new banner axis for all of
' the simple categorical variable instances
For Each MyVariableInstance in TableDoc.DataSet.MDMDocument.Variables
' Exclude grid, loop and helper variables and temporary or dummy variables that contain no data
If MyVariableInstance.DataType = mr.Categorical _
And MyVariableInstance.HasCaseData = True _
And MyVariableInstance.IsSystemVariable = False _
And BitAnd(MyVariableInstance.UsageType, 31) = 0 Then
MyCounter = MyCounter + 1
MyTableName = "Table" + CText(MyCounter)
MyTableSpec = MyVariableInstance.FullName + " * axis(MyBanner)"
MyTableDescription = MyVariableInstance.FullName
TableDoc.Tables.AddNew(MyTableName, MyTableSpec, MyTableDescription)
End If
Next
This example checks whether the variable is a simple variable by using the BitAnd function to test the bits set in the VariableInstance.UsageType property. The value 31 represents the combination of the following VariableUsageConstants: vtHelperField (16), vtGrid (1), vtCompound (2), vtClass (4), and vtArray (8). The test makes sure that none of these bits is set, which means that the variable instance is not inside a Grid, Class, Compound, or Array object, or in a HelperFields collection.
Requirements
UNICOM Intelligence Reporter
Next
Defining your first filter
See also
Getting started