In This Section:
Understanding Elements of a Query
Working with Levels and Generations
Using a Slicer Axis to Set Query Point-of-View
Creating and Using Named Sets and Calculated Members
MDX, the data manipulation language for Essbase, is a joint specification of the XML for Analysis founding members. See http://www.xmla.org.
To complete the exercises in this chapter, which are based on the Sample.Basic database, use the MaxL Shell. Before continuing, start Essbase and log on to MaxL Shell. Additionally, be prepared to use a text editor to create the sample queries as presented in this chapter.
In this section you will create a template to use as a basis for developing simple queries.
Most queries can be built upon the following grammatical framework:
SELECT {} ON COLUMNS FROM Sample.Basic
SELECT in line 1 is the keyword that begins the main body of all MDX statements.
The braces { } in line 2 are a placeholder for a set. In the above query, the set is empty, but the braces remain as a placeholder.
To create a query template:
Create a folder to store sample queries that can be run against the Sample.Basic database.
For example, create a folder called “queries” under the ARBORPATH/app/Sample/Basic directory of the Essbase installation.
Using a text editor, type the following code into a blank file:
SELECT {} ON COLUMNS FROM Sample.Basic
A set is an ordered collection of one or more tuples that have the same dimensionality (see Rules for Specifying Sets for an explanation of dimensionality).
A tuple is a way to refer to a member or a member combination from any number of dimensions. For example, in the Sample.Basic database, Jan is a tuple, as is (Jan, Sales), as is ([Jan],[Sales],[Cola],[Utah],[Actual]).
The member name can be specified in these ways:
By specifying the actual name or the alias; for example:
Cola
Actual
COGS
[100]
If the member name starts with number or contains spaces, it should be within brackets; for example, [100]. Brackets are recommended for all member names, for clarity and code readability.
If the member name starts with an ampersand (&) , it should be within quotation marks; for example, ["&xyz"]. This is because the leading ampersand is reserved for substitution variables (see Using Substitution Variables in MDX Queries). You can also specify it as StrToMbr("&100").
For attribute members, the long name (qualified to uniquely identify the member) should be used; for example, [Ounces_12] instead of [12].
By specifying dimension name or any one of the ancestor member names as a prefix to the member name; for example, [Product].[100-10] and [Diet].[100-10]. This practice is recommended for all member names, as it eliminates ambiguity and enables you to refer accurately to shared members.
By specifying the name of a calculated member defined in the WITH section.
Recall that the braces { } in line 2 of your query template are a placeholder for a set. In this exercise, we will add a set to the query and run it.
To run the query:
Because a set can be as simple as one tuple, add Jan as a set to the query template. Retain the braces (required for all set specifications except for sets that are produced by a function call).
Type Jan inside the braces in line 2:
SELECT
{Jan}
ON COLUMNS
FROM Sample.Basic
Ensure that Essbase is started (the essbase.exe process is running).
In order for Essbase to receive MDX statements, pass the statements to Essbase using either the MaxL Shell or MDX Script Editor in Administration Services. The examples in this chapter use the MaxL Shell.
Start the MaxL Shell and log on with a valid user name and password. For example,
essmsh -l admin passwd
Copy and paste the entire SELECT query into the MaxL Shell, but do not press Enter yet.
Enter a semicolon at the end, anywhere after Basic but before pressing Enter. The semicolon is not part of MDX syntax requirements, but it is required by MaxL Shell to indicate the end of a statement that is ready to execute.
Note: | If you are using the MDX Script Editor in Administration Services, do not terminate with a semicolon. |
Results: The results should be similar to the following:
Jan 8024
As described previously, a set is an ordered collection of one or more tuples.
For example, in the following query, {[100-10]} is a set consisting of one tuple.
SELECT {[100-10]} ON COLUMNS FROM Sample.Basic
In the following query, {([100-10], [Actual])} is a also a set consisting of one tuple, though in this case, the tuple is not one member name. Rather, ([100-10], [Actual]) represents a tuple consisting of members from two dimensions, Product and Scenario.
SELECT {([100-10], [Actual])} ON COLUMNS FROM Sample.Basic
When a set has multiple tuples, the following rule applies: In each tuple of the set, members must represent the same dimensions as do the members of other tuples of the set. Additionally, the dimensions must be represented in the same order. In other words, each tuple of the set must have the same dimensionality. For example:
The following set consists of two tuples of the same dimensionality:
{(West, Feb), (East, Mar)}
The following set breaks the dimensionality rule, because Feb and Sales are from different dimensions:
{(West, Feb), (East, Sales)}
The following set breaks the dimensionality rule, because although the two tuples contain the same dimensions, the order of dimensions is reversed in the second tuple:
{(West, Feb), (Mar, East)}
A set can also be a collection of sets, or it can be empty (containing no tuples).
A set must be enclosed in braces {}, except in cases where the set is represented by an MDX function that returns a set.
An axis is a specification determining the layout of query results from a database. Axes fit into MDX queries as follows:
SELECT <axis> [, <axis>...] FROM <database>
At least one axis must be specified in any MDX query.
Up to 64 axes may be specified, beginning with AXIS(0) and continuing with AXIS(1)...AXIS(63). Using more than three axes is uncommon. The order of axes is not important; however, when a set of axes 0 through n are specified, no axis between 0 and n should be skipped. Additionally, a dimension cannot appear on multiple axes.
The first five axes have keyword aliases, as listed in Table 110:
For example, in the following query, the axis specification is {Jan}ON COLUMNS:
SELECT {Jan} ON COLUMNS FROM Sample.Basic
To run a two-axis query:
Add a comma after ON COLUMNS; then add a placeholder for a second axis by adding ON ROWS:
SELECT {} ON COLUMNS, {} ON ROWS FROM Sample.Basic
As the set specification for the column axis, enter the Product members 100-10 and 100-20. For example:
SELECT
{[100-10],[100-20]}
ON COLUMNS,
{}
ON ROWS
FROM Sample.Basic
Because these member names contain special characters, you must use brackets. The convention used here, to enclose all member names in brackets even if they do not contain special characters, is recommended.
As the set specification for the row axis, enter the Year members Qtr1 through Qtr4.
SELECT
{[100-10],[100-20]}
ON COLUMNS,
{[Qtr1],[Qtr2],[Qtr3],[Qtr4]}
ON ROWS
FROM Sample.Basic
Paste the query into the MaxL Shell and run it, as described in Exercise: Running Your First Query.
Results of the query are shown in Table 111:
To query multiple dimensions on a single axis:
On the column axis, specify two tuples, each of which is a member combination rather than a single member. Enclose each tuple in parentheses, because multiple members are represented in each tuple.
SELECT
{([100-10],[East]), ([100-20],[East])}
ON COLUMNS,
{}
ON ROWS
FROM Sample.Basic
On the row axis, specify four two-member tuples, nesting each Quarter with Profit:
SELECT {([100-10],[East]), ([100-20],[East])} ON COLUMNS, { ([Qtr1],[Profit]), ([Qtr2],[Profit]), ([Qtr3],[Profit]), ([Qtr4],[Profit]) } ON ROWS FROM Sample.Basic
Paste the query into the MaxL Shell and run it, as described in Exercise: Running Your First Query.
Results of the query are shown in Table 112:
A cube specification is the part of the query that determines which database is being queried. The cube specification fits into an MDX query as follows:
SELECT <axis> [, <axis>...]
FROM <database>
The <database> section follows the FROM keyword and should consist of delimited or nondelimited identifiers that specify first an application name and a then database name; for example, the following specifications are valid:
FROM Sample.Basic
FROM [Sample.Basic]
FROM [Sample].[Basic]
FROM'Sample'.'Basic'
Rather than creating sets member-by-member or tuple-by-tuple, you can use a function that returns a set. MDX includes several functions that return sets and several functions that return other values. For a complete reference of MDX functions supported by Essbase, see the MaxL section of the online Oracle Essbase Technical Reference.
The MemberRange function returns a range of members inclusive of and between two specified members of the same generation. Its syntax is as follows:
MemberRange (member1, member2, [,layertype])
where the first argument you provide is the member that begins the range, and the second argument is the member that ends the range. The layertype argument is optional. See the Oracle Essbase Technical Reference.
An alternate syntax for MemberRange is to use a colon between the two members, instead of using the function name: member1 : member2. |
To use the MemberRange function:
Delete the braces {}, which are unnecessary when you are using a function to return the set.
Use the colon operator to select a member range of Qtr1 through Qtr4:
SELECT
[Qtr1]:[Qtr4]
ON COLUMNS
FROM Sample.Basic
Paste the query into the MaxL Shell and run it, as described in Exercise: Running Your First Query.
Use the MemberRange function to select the same member range, Qtr1 through Qtr4.
SELECT
MemberRange([Qtr1],[Qtr4])
ON COLUMNS
FROM Sample.Basic
Paste the query into the MaxL Shell and run it, as described in Exercise: Running Your First Query.
Results: The same results should be returned when running the queries listed in step 3 and step 5.
The CrossJoin function returns the cross product of two sets from different dimensions. Its syntax is as follows:
CrossJoin(set,set)
The CrossJoin function takes two sets from different dimensions as input and creates a set that is a cross product of the two input sets, useful for creating symmetric reports.
To use the CrossJoin function:
Replace the braces {} from the columns axis with CrossJoin().
SELECT CrossJoin () ON COLUMNS, {} ON ROWS FROM Sample.Basic
Add two comma-separated pairs of braces as placeholders for the two set arguments you will provide to the CrossJoin function:
SELECT
CrossJoin ({}, {})
ON COLUMNS,
{}
ON ROWS
FROM Sample.Basic
In the first set, specify the Product member [100-10]. In the second set, specify the Market members [East], [West], [South], and [Central].
SELECT CrossJoin ({[100-10]}, {[East],[West],[South],[Central]}) ON COLUMNS, {} ON ROWS FROM Sample.Basic
On the row axis, use CrossJoin to cross a set of Measures members with a set containing Qtr1:
Paste the query into the MaxL Shell and run it, as described in Exercise: Running Your First Query.
When using CrossJoin, the order of arguments affects the order of tuples in the output.
Results of the query are shown in Table 113:
The Children function returns a set of all child members of the given member. Use this syntax:
Children (member)
An alternate syntax for Children is to use it like an operator on the input member, as follows: member.Children. We will use the operator syntax in this exercise. |
To use the Children function to introduce a shortcut in the first axis specification:
In the second set of the column axis specification, replace [East],[West],[South],[Central] with [Market].Children.
SELECT
CrossJoin ({[100-10]}, {[Market].Children})
ON COLUMNS,
CrossJoin (
{[Sales],[COGS],[Margin %],[Profit %]}, {[Qtr1]}
)
ON ROWS
FROM Sample.Basic
Paste the query into the MaxL Shell and run it, as described in Exercise: Running Your First Query.
Results: You should see the same results as those shown in returned for Table 113, Results: Using the CrossJoin Function.
In MDX, layer refers to generations and levels in an Essbase hierarchy.
In Essbase, generation numbers begin counting with 1 at the dimension name; higher generation numbers are those closest to leaf members in a hierarchy.
Level numbers begin with 0 at the leaf-most part of the hierarchy, and the highest level number is a dimension name.
A number of MDX functions take a layer you specify as an input argument and perform set operations based on the generation or level represented in the layer argument.
You can specify a layer argument in the following ways:
The dimension name along with the generation or level name; for example, Market.Regions and [Market].[States].
The Levels function with a dimension and a level number as input. For example, [Year].Levels(0).
The Level function with a member as input. For example, [Qtr1].Level returns the level of quarters in Sample.Basic, which is level 1 of the Market dimension.
The Generations function with a dimension and a generation number as input. For example, [Year].Generations (3).
The Generation function with a member as input. For example, [Qtr1].Generation returns the generation of quarters in Sample.Basic, which is generation 2 of the Market dimension.
In the Sample.Basic database, Qtr1 and Qtr4 are in the same layer. This means that Qtr1 and Qtr4 are also in the same generation. However, in a different database with a ragged hierarchy, Qtr1 and Qtr4 might not necessarily be in the same level, although they are in the same generation. For example, if the hierarchy of Qtr1 drills down to weeks, and the hierarchy of Qtr4 stops at months, Qtr1 is one level higher than Qtr4, but they are still in the same layer. |
The Members function can be used to return all members of a specified generation or level. Its syntax when used with a layer argument:
where the layer argument you provide indicates the generation or level of members you want returned.
To use the Members function:
Use the Members function and the Levels function to select all level 0 members in the Market dimension of Sample.Basic:
SELECT
Members(Market.levels(0))
ON COLUMNS
FROM Sample.Basic
Paste the query into the MaxL Shell and run it, as described in Exercise: Running Your First Query.
A slicer axis is a way to limit a query to apply to only a specific area of the database. The optional slicer, if used, must be in the WHERE section of an MDX query. Furthermore, the WHERE section must be the last component of the query, following the cube specification (the FROM section):
SELECT {set} ON axes FROM database WHERE slicer
Use the slicer axis to set the context of the query; it is usually the default context for all the other axes.
For example, for a query to select only Actual Sales in the Sample.Basic database, excluding budgeted sales, the WHERE clause might look like the following:
WHERE ([Actual], [Sales])
Because (Actual, Sales) is specified in the slicer axis, you need not include them in the ON AXIS(n) set specifications.
To use the slicer axis to limit results:
Paste the query into the MaxL Shell and run it, as described in Exercise: Running Your First Query.
Note the results in one of the data cells; for example, notice that the first tuple, ([100-10],[East],[Sales],[Qtr1]), has a value of 5731.
Add a slicer axis to limit the data returned to budgeted values only.
SELECT
CrossJoin ({[100-10]}, {[East],[West],[South],[Central]})
ON COLUMNS,
CrossJoin (
{[Sales],[COGS],[Margin %],[Profit %]}, {[Qtr1]}
)
ON ROWS
FROM Sample.Basic
WHERE (Budget)
Results: You should see different results for the queries listed in step 1 and step 3.
Table 114 lists the relationship functions that return sets based on member relationships in the database outline:
Table 115, List of Relationship Functions That Return a Single Member lists the relationship functions that return a single member rather than a set:
Table 115. List of Relationship Functions That Return a Single Member
Returns a child member at the same position as a member from another ancestor. | |
For examples using relationship functions, see the MDX examples in the MaxL section of the Oracle Essbase Technical Reference.
Table 116 lists the set functions that operate on input sets without deriving further information from a database:
Table 116. List of Pure Set Functions
The Intersect function returns the intersection two input sets, optionally retaining duplicates. Syntax:
Intersect (set, set [,ALL])
Use the Intersect function to compare sets by finding tuples that are present in both sets.
To use the Intersect function:
Delete the braces {} from the axis, and replace them with Intersect() . For example:
SELECT
Intersect (
)
ON COLUMNS
FROM Sample.Basic
Add two comma-separated pairs of braces to use as placeholders for the two set arguments you will provide to the Intersect function. For example:
SELECT
Intersect (
{ },
{ }
)
ON COLUMNS
FROM Sample.Basic
Specify children of East as the first set argument. For example:
SELECT
Intersect (
{ [East].children },
{ }
)
ON COLUMNS
FROM Sample.Basic
For the second set argument, specify all members of the Market dimension that have a UDA of “Major Market.” For example:
SELECT
Intersect (
{ [East].children },
{ UDA([Market], "Major Market") }
)
ON COLUMNS
FROM Sample.Basic
Paste the query into the MaxL Shell and run it, as described in Exercise: Running Your First Query.
Results: All children of East that have a UDA of “Major Market” are returned. For example:
New York Massachusetts Florida 8202 6172 5029
The Union function joins two input sets, optionally retaining duplicates. Syntax:
Union (set, set [,ALL])
Use the Union function to lump two sets together into one set.
Results: A comparison of theses query results with the results using the Intersect function (see Exercise: Using the Intersect Function) shows that while Intersect returns a set containing only those children of East that have a UDA of “Major Market,” Union returns {all children of east) + (all Market Members that have a UDA of “Major Market”).
For more examples using pure set-operative functions, see the Oracle Essbase Technical Reference.
Calculated members and named sets are logical entities in query that can be used multiple times during the life of the query. Calculated members and named sets can save time in lines of code written as well as in execution time. The optional WITH section at the beginning of an MDX query is where you define the calculated members and/or named sets.
A calculated member is a hypothetical member that exists for the duration of the query execution. Calculated members enable complex analysis without necessitating adding new members to the database outline. Calculated members are a storage place for calculation results performed on actual members.
Use the following guidelines for calculated member names:
Associate the calculated member with a dimension; for example, to associated the member MyCalc with the Measures dimension, name it [Measures].[MyCalc].
Do not use actual member names to name calculated members; for example, do not name a calculated member [Measures].[Sales], because Sales already exists in the Measures dimension.
Setting the solve order for each calculated member is recommended when you use multiple calculated members to create ratios or custom totals. For more information about solve order, see the MDX section of the Oracle Essbase Technical Reference.
This exercise includes the Max function, a common function for calculations. The Max function returns the maximum of values found in the tuples of a set. Its syntax is as follows:
Max (set, numeric_value)
To create a calculated member:
On the row axis set, specify the children of Product. For example:
SELECT
{}
ON COLUMNS,
{[Product].children}
ON ROWS
FROM Sample.Basic
At the beginning of the query, add a placeholder for the calculated member specification. For example:
WITH MEMBER [].[]
AS ''
SELECT
{}
ON COLUMNS,
{[Product].children}
ON ROWS
FROM Sample.Basic
To associate the calculated member with the Measures dimension and name it Max Qtr2 Sales, add this information to the calculated member specification. For example:
WITH MEMBER [Measures].[Max Qtr2 Sales] AS '' SELECT {} ON COLUMNS, {[Product].children} ON ROWS FROM Sample.Basic
After the AS keyword and inside the single quotation marks, define the logic for the calculated member named Max Qtr2 Sales.
Use the Max function with the set to evaluate (Qtr2) as the first argument, and the measure to evaluate (Sales) as the second argument. For example:
WITH MEMBER [Measures].[Max Qtr2 Sales] AS ' Max ( {[Year].[Qtr2]}, [Measures].[Sales] )' SELECT {} ON COLUMNS, {[Product].children} ON ROWS FROM Sample.Basic
The calculated member Max Qtr2 Sales is defined in the WITH section. To use it in a query, include it on one of the axes in the SELECT portion of the query. Select the predefined calculated member on the columns axis. For example:
WITH MEMBER [Measures].[Max Qtr2 Sales]
AS '
Max (
{[Year].[Qtr2]},
[Measures].[Sales]
)'
SELECT
{[Measures].[Max Qtr2 Sales]}
ON COLUMNS,
{[Product].children}
ON ROWS
FROM Sample.Basic
Paste the query into the MaxL Shell and run it, as described in Exercise: Running Your First Query.
Results of the query are shown in Table 117:
You define named sets in the WITH section of the query. Doing so is useful because you can reference the set by name when building the SELECT section of the query.
For example, the named set Best5Prods identifies a set of the five top-selling products in December:
WITH SET [Best5Prods] AS 'Topcount ( [Product].members, 5, ([Measures].[Sales], [Scenario].[Actual], [Year].[Dec]) )' SELECT [Best5Prods] ON AXIS(0), {[Year].[Dec]} ON AXIS(1) FROM Sample.Basic
Table 118 lists the functions that loop through sets of data, and perform search conditions and results that you specify:
Table 118. List of Iterative Functions
The following query returns all Market dimension members for which the expression IsChild([Market].CurrentMember,[East]) returns TRUE; the query returns all children of East.
SELECT Filter([Market].Members, IsChild([Market].CurrentMember,[East]) ) ON COLUMNS FROM Sample.Basic
The Filter function in MDX is comparable to the RESTRICT command in Report Writer.
For more examples of Filter and other iterative functions, see the Oracle Essbase Technical Reference.
When you are querying on a database, you can use the NON EMPTY keywords at the beginning of an axis specification to prevent cells containing no value from being included the result of the query.
The axis specification syntax including NON EMPTY:
<axis_specification> ::=
[NON EMPTY] <set> ON
COLUMNS | ROWS | PAGES | CHAPTERS |
SECTIONS | AXIS (<unsigned_integer>)
Including the optional keywords NON EMPTY before the set specification in an axis causes suppression of slices in that axis that would contain entirely #MISSING values.
For any given tuple on an axis (such as (Qtr1, Actual)), a slice consists of the cells arising from combining this tuple with all tuples of all other axes. If all of these cell values are #MISSING, the NON EMPTY keyword causes elimination of the tuple.
For example, if even one value in a row is not empty, the entire row is returned. Including NON EMPTY at the beginning of the row axis specification would eliminate the following row slice from the set returned by a query:
In addition to suppressing missing values with NON EMPTY, you can use the following MDX functions to handle #MISSING results:
For more information, see the MDX section of the Oracle Essbase Technical Reference.
Substitution variables act as global placeholders for information that changes regularly; you set the substitution variables on the server through Administration Services, MaxL, or ESSCMD and assign a value to each variable. You can change the value anytime. You must have the role of at least Database Manager to set substitution variables. See Using Substitution Variables.
The substitution variable must be accessible from the application and database you are querying.
A substitution variable has two components: the name and the value.
The variable name can be an alphanumeric combination whose maximum size is specified in Limits. Do not use spaces, punctuation, or brackets ([ ]) in substitution variable names used in MDX.
At the point in the expression where you want to use the variable, show the variable name preceded by an ampersand (&); for example, where CurMonth is the name of the substitution variable set on the server, include &CurMonth in the MDX expression.
When you perform the retrieval, Essbase replaces the variable name with the substitution value, and that value is used by the MDX expression.
For example, the expression is written showing the variable name CurQtr preceded with the &:
SELECT
{[&CurQtr]}
ON COLUMNS
FROM Sample.Basic
When the expression is executed, the current value (Qtr1) is substituted for the variable name, and the expression that is executed is:
SELECT
{[Qtr1]}
ON COLUMNS
FROM Sample.Basic
In MDX, properties describe certain characteristics of data and metadata. MDX enables you to write queries that use properties to retrieve and analyze data. Properties can be intrinsic or custom.
Intrinsic properties are defined for members in all dimensions. The intrinsic member properties defined for all members in an Essbase database outline are MEMBER_NAME, MEMBER_ALIAS, LEVEL_NUMBER, and GEN_NUMBER.
MDX in Essbase supports two types of custom properties: attribute properties and UDA properties. Attribute properties are defined by the attribute dimensions in an outline. In the Sample.Basic database, the Pkg Type attribute dimension describes the packaging characteristics of members in the Product dimension. This information can be queried in MDX using the property name [Pkg Type].
Attribute properties are defined only for specific dimensions and only for a specific level in each dimension. For example, in the Sample.Basic outline, [Ounces] is an attribute property defined only for members in the Product dimension, and this property has valid values only for the level 0 members of the Product dimension. The [Ounces] property does not exist for other dimensions, such as Market. The [Ounces] property for a non level 0 member in the Product dimension is a NULL value. The attribute properties in an outline are identified by the names of attribute dimensions in that outline.
The custom properties also include UDAs. For example, [Major Market] is a UDA property defined on Market dimension members. It returns a TRUE value if [Major Market] UDA is defined for a member, and FALSE otherwise.
Properties can be used inside an MDX query in two ways.
You can list the dimension and property combinations for each axis set. When a query is executed, the specified property is evaluated for all members from the specified dimension and included in the result set.
For example, on the column axis, the following query returns the GEN_NUMBER information for every Market dimension member. On the row axis, the query returns MEMBER_ALIAS information for every Product dimension member.
SELECT [Market].Members DIMENSION PROPERTIES [Market].[GEN_NUMBER] on columns, Filter ([Product].Members, Sales > 5000) DIMENSION PROPERTIES [Product].[MEMBER_ALIAS] on rows FROM Sample.Basic
When querying for member properties using the DIMENSION PROPERTIES section of an axis, a property can be identified by the dimension name and the name of the property, or by using the property name itself. When a property name is used by itself, that property information is returned for all members from all dimensions on that axis, for which that property applies. In the following query, the MEMBER_ALIAS property is evaluated on the row axis for Year and Product dimensions.
SELECT [Market].Members DIMENSION PROPERTIES [Market].[GEN_NUMBER] on columns, CrossJoin([Product].Children, Year.Children) DIMENSION PROPERTIES [MEMBER_ALIAS] on rows FROM Sample.Basic
Properties can be used inside value expressions in an MDX query. For example, you can filter a set based on a value expression that uses properties of members in the input set.
The following query returns all caffeinated products that are packaged in cans.
SELECT Filter([Product].levels(0).members, [Product].CurrentMember.Caffeinated and [Product].CurrentMember.[Pkg Type] = "Can") xDimension Properties [Caffeinated], [Pkg Type] on columns FROM Sample.Basic
The following query calculates the value [BudgetedExpenses] based on whether the current Market is a major market, using the UDA [Major Market].
WITH MEMBER [Measures].[BudgetedExpenses] AS 'IIF([Market].CurrentMember.[Major Market], [Marketing] * 1.2, [Marketing])' SELECT {[Measures].[BudgetedExpenses]} ON COLUMNS, [Market].Members ON ROWS FROM Sample.Basic WHERE ([Budget])
The value of an MDX property in Essbase can be a numeric, Boolean, or string type. MEMBER_NAME and MEMBER_ALIAS properties return string values. LEVEL_NUMBER, and GEN_NUMBER properties return numeric values.
The attribute properties return numeric, Boolean, or string values based on the attribute dimension type. For example, in Sample.Basic, the [Ounces] attribute property is a numeric property. The [Pkg Type] attribute property is a string property. The [Caffeinated] attribute property is a Boolean property.
Essbase allows attribute dimensions with date types. The date type properties are treated as numeric properties in MDX. When comparing these property values with dates, use the TODATE function to convert date strings to numeric before comparison.
The following query returns all Product dimension members that have been introduced on date 03/25/2007. Because the property [Intro Date] is a date type, the TODATE function must be used to convert the date string “03-25-2007” to a number before comparing it.
SELECT Filter ([Product].Members, [Product].CurrentMember.[Intro Date] = TODATE("mm-dd-yyyy","03-25-2007"))ON COLUMNS FROM Sample.Basic
When a property is used in a value expression, you must use it appropriately based on its value type: string, numeric, or Boolean.
You can also query attribute dimensions with numeric ranges.
The following query retrieves Sales data for Small, Medium, and Large population ranges.
SELECT {Sales} ON COLUMNS, {Small, Medium, Large} ON ROWS FROM Sample.Basic
When attributes are used as properties in a value expression, you can use range members to check whether a member's property value falls within a given range, using the IN operator.
For example, the following query returns all Market dimension members with the population range in Medium:
SELECT Filter( Market.Members, Market.CurrentMember.Population IN "Medium" ) ON AXIS(0) FROM Sample.Basic
Not all members may have valid values for a given property name. For example, the MEMBER_ALIAS property returns an alternate name for a given member as defined in the outline; however, not all members may have aliases defined. In these cases A NULL value is be returned for those members that do not have aliases.
SELECT [Year].Members DIMENSION PROPERTIES [MEMBER_ALIAS] ON COLUMNS FROM Sample.Basic
none of the members in the Year dimension have aliases defined for them. Therefore, the query returns NULL values for the MEMBER_ALIAS property for members in the Year dimension.
The attribute properties are defined for members of a specific dimension and a specific level in that dimension. In the Sample.Basic database, the [Ounces] property is defined only for level 0 members of the Product dimension.
Therefore, if you query for the [Ounces] property of a member from the Market dimension, as shown in the following query, you will get a syntax error:
SELECT Filter([Market].members, [Market].CurrentMember.[Ounces] = 32) ON COLUMNS FROM Sample.Basic
Additionally, if you query for the [Ounces] property of a non level 0 member of the dimension, you will get a NULL value.
When using property values in value expressions, you can use the function IsValid() to check for NULL values. The following query returns all Product dimension members with an [Ounces] property value of 12, after eliminating members with NULL values.
SELECT Filter([Product].Members, IsValid([Product].CurrentMember.[Ounces]) AND [Product].CurrentMember.[Ounces] = 12) ON COLUMNS FROM Sample.Basic