Databases Reference
In-Depth Information
NOTE
The
Scope
statement is static: It is evaluated just once—when the script is loaded in
the cube—and is not reevaluated for each query. We highly recommend using the
power of the
Scope
operator and putting the more computation-intensive expressions in
the
Scope
operator or in the <
sub_cube_expression
> of the assignment operator rather
than in the rightmost part of the assignment.
When you define an assignment operator inside of a
Scope
statement, you can use the
This
operator to assign an expression to the whole subcube defined by the
Scope
state-
ment.
Nested
Scope
Statements
You can define a
Scope
statement inside another
Scope
statement to create nested
Scope
statements. (Conceptually, this is true even for an initial
Scope
statement created inside
the scope of a whole cube.) A nested
Scope
statement inherits some of the attributes from
a parent
Scope
statement. The rules of inheritance are somewhat similar to the rules of
coordinate overwrites and of strong relationships (see Chapters 10, “MDX Concepts,” and
11, “Advanced MDX”). Both sets of inheritance rules depend on the relationships
between attributes, but differences between the rules exist and are worth discussing. (For a
deeper discussion about attribute relationships, see Chapter 5, “Dimensions in the
Conceptual Model.”)
.
If a subcube definition of a nested
Scope
statement explicitly specifies an attribute, it
overwrites the subcube's coordinate that corresponds to that attribute. For example,
if you have the following
Scope
statements, the
Country
attribute
USA
changes to
Canada
, and the subcube that corresponds to stores in Canada takes on the value
1
:
Scope ([Store].[Stores].[Store Country].[USA]);
Scope ([Store].[Stores].[Store Country].[Canada]);
//The scope is on [Store].[Stores].[Store Country].[Canada]
This = 1;
End Scope;
End Scope;
.
An attribute specified by a nested
Scope
statement does not overwrite its related (on
top of the current one) attribute. This is the primary difference with rules for coordi-
nate overwrites.
For example, the following
Scope
statements, in which the parent statement has a
slice on the
Country
attribute and the nested
Scope
statement has a slice on the
State
attribute, do not overwrite the attribute
Country
, which is related to the
State
attribute. They assign the value
1
to the subcube that corresponds to the
CrossJoin([Store].[Stores].[Store Country].[USA], [Store].[Stores].[Store
State].[WA])
set.
Search WWH ::
Custom Search