Developing Formulas on Aggregate Storage Outlines
Formulas calculate relationships between members in a database outline. If you are familiar with using formulas on block storage outlines, consider the following differences when using formulas on aggregate storage outlines:
-
Essbase provides a native calculation language to write formulas on block storage outlines. To write formulas for aggregate storage outlines, use the MDX (Multidimensional Expressions) language.
-
Apply formulas directly to members in the database outline. For block storage databases, formulas can be placed in a calculation script. For aggregate storage databases, you cannot place formulas in a calculation script.
This chapter concentrates on using MDX to write formulas on aggregate storage databases. For information about using MDX to write queries, see Writing MDX Queries. For information about writing formulas for block storage outlines, see Developing Formulas for Block Storage Databases. For MDX syntax details, see MDX.
Using MDX Formulas
An MDX formula must always be an MDX numeric value expression. In MDX, a numeric value expression is any combination of functions, operators, and member names that does one of the following actions:
-
Calculates a value
-
Tests for a condition
-
Performs a mathematical operation
A numeric value expression is different from a set expression. A set expression is used on query axes and describes members and member combinations. A numeric value expression specifies a value.
A numeric value expression is used in queries to build calculated members, which are logical members created for analytical purposes in the WITH section of the query, but which do not exist in the outline.
The following query defines a calculated member and uses a numeric value expression to provide a value for it:
WITH MEMBER
[Measures].[Prod Count]
AS
'Count (
Crossjoin (
{[Units]},
{[Products].children}
)
)', SOLVE_ORDER=1
SELECT
{[Geography].children}
ON COLUMNS,
{
Crossjoin (
{[Units]},
{[Products].children}
),
([Measures].[Prod Count], [Products])
}
ON ROWS
FROM
ASOsamp.Sample
In the sample query, the WITH clause defines a calculated member, Product Count, in the Measures dimension, as follows:
WITH MEMBER
[Measures].[Prod Count]
The numeric value expression follows the WITH clause and is enclosed in single quotation marks. In the sample query, the numeric value expression is specified as follows:
'Count (
Crossjoin (
{[Units]},
{[Products].children}
)
)'
The SOLVE_ORDER property specifies the order in which members and formulas are evaluated. See Calculation Order.
Note:
For an explanation of the syntax rules used to build the numeric value expression in the example, see the documentation for the Count, CrossJoin, and Children functions.
A numeric value expression also can be used as an MDX formula to calculate the value of an existing outline member.
Therefore, rather than creating the example query, you can create an outline member on the Measures dimension called Prod Count that is calculated in the outline in the same way that the hypothetical Prod Count was calculated in the sample query.
To create a calculated member with a formula:
Before applying formulas to members in the outline, you can write MDX queries that contain calculated members. When you can write an MDX query that returns the calculated member results that you want, you are ready to apply the logic of the numeric value expression to an outline member and validate and test the expression. See Writing MDX Queries.
Formula Calculation for Aggregate Storage Databases
Essbase calculates formulas in aggregate storage outlines only when data is retrieved. Calculation order may affect calculation results. Whenever you use MDX formulas on multiple dimensions in an aggregate storage outline, it is good practice to set the solve order for each member or dimension. See Calculation Order.
Note:
When designing an aggregate storage database calculation, consider that aggregate storage database members with MDX formulas are dynamically calculated. The dynamically calculated members have a value of #MISSING until they are queried.
Formula Syntax for Aggregate Storage Databases
When you create member formulas for aggregate storage outlines, observe the following rules:
-
Enclose member names in brackets (
[]
) if they meet any of the following conditions:-
Start with a number or contains spaces; for example,
[100]
. Brackets are recommended for all member names, for clarity and code readability. -
Are the same as an operator or function name.
-
Include a nonalphanumeric character; for example, a hyphen (
-
), an asterisk (*
), or a slash (/
).
Note:
In formulas, member names starting with
$
or&
must be enclosed in quotation marks as well as brackets. For example,$testmember
would be expressed in the formula as["$testmember"]/100
-
-
Use the IIF function to write conditional tests with a single else condition. The syntax for the IIF function does not require an ELSEIF keyword to identify the else condition nor an ENDIF keyword to terminate the statement. You can nest IIF functions to create a more complex formula.
-
Use the Case, WHEN, THEN construct to write conditional tests with multiple conditions.
-
Be certain that tuples are specified correctly. A tuple is a collection of members with the restriction that no two members can be from the same dimension. Enclose tuples in parentheses; for example,
(Actual,
Sales)
. -
Be certain that sets are specified correctly. A set is an ordered collection of one or more tuples. 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, all tuples of the set must have the same dimensionality.
See Rules for Specifying Sets.
Enclose sets in braces, for example:
{ [Year].[Qtr1], [Year].[Qtr2], [Year].[Qtr3], [Year].[Qtr4] }
Creating Formulas on Aggregate Storage Outlines
Formulas are plain text. You can type the formulas directly into the formula editor, or you can create a formula in any text editor and paste the text into the formula editor.
MDX-based syntax checking tells you about syntax errors in formulas; for example, a mistyped function name or a nonexistent member. Unknown member names can be validated against a list of function names. If you are not connected to the service instance or to the application associated with the outline, Essbase may connect you to validate unknown names.
Syntax checking occurs when validate or save a formula. Errors are displayed in the user interface. If an error occurs, you choose to save or not save the formula. If you save a formula with errors, you are warned when you save the outline. When you calculate a formula with errors, the formula is ignored and the member is given a value of $MISSING.
A syntax checker cannot warn you of semantic errors in a formula. Semantic errors occur when a formula does not work as you expect. One way to find semantic errors in a formula is to place the numeric value expression that defines the formula into a query and run the query to verify that the results are as you expect. See Using MDX Formulas to see how to place a formula into a query.
You can include formulas in a dimension build data source. See Setting Field Type Information.
Composing Formulas on Aggregate Storage Outlines
The following topics in this section discusses and give examples of how to write a variety of formulas for members in aggregate storage outlines.
Basic Equations for Aggregate Storage Outlines
You can apply a mathematical operation to a formula to create a basic equation. For example, the following formula is applied to the Avg Units/Transaction member in the ASOsamp.Sample database:
[Units]/[Transactions]
The formula in Avg Units/Transaction divides the number of units by the number of transactions to arrive at the average number of units per transaction.
In aggregate storage outlines, members cannot be tagged as expense items. Therefore, functions in Calc, such as @VAR and @VARPER, which determine the difference between two members by considering expense tags, are not relevant in aggregate storage outlines.
The MDX subtraction operator can be used to calculate the difference between two members. For example, the following formula can be applied to a new member, called Price Diff, in ASOsamp.Sample, to calculate the difference between the price paid and the original price:
[Price Paid]-[Original Price]
Members Across Dimensions in Aggregate Storage Outlines
ASOsamp.Sample provides a formula on a member called % of Total. This member formula identifies the percentage of the Measures total that is produced by Transactions. The formula for % of Total:
Transactions/
(Transactions,Years,Months,[Transaction Type],[Payment Type],
Promotions,Age,[Income Level],Products,Stores,Geography)
The formula specifies a member (Transactions) divided by a tuple (Transactions, Years, ...). The formula lists a top member from every dimension to account for all Transaction data in the cube; that is, not Transaction data for the Curr Year member but Transaction data for all members of the Years dimension, not Transaction data for months in the first two quarters but Transaction for all months, and so on. In this way, the value of % of Total represents the percentage of the Measures total that are produced by Transactions.
Conditional Tests in Formulas for Aggregate Storage Outlines
You can define a formula that uses a conditional test or a series of conditional tests to determine the value for a member. Use the IIF function to perform a test with one else condition. You can nest IIF functions to create a more complex query.
The example specifies a formula for a member that represents the price the company must pay for credit card transactions, which includes a 5% charge. The following example assumes that the Credit Price member has been added to the Measures dimension of the ASOsamp.Sample database. Credit Price has the following formula, which adds 5% to Price Paid when the payment type is a credit card.
IIF (
[Payment Type].CurrentMember=[Credit Card],
[Price Paid] * 1.05, [Price Paid]
)
Use the CASE, WHEN, THEN construct to create formulas with multiple tests and else conditions.
The Filter function returns the tuples of the input set that meet the criteria of the specified search condition. For example, to establish a baseline (100) for all products, you can add a Baseline member and create a formula for it, as follows:
Count(Filter(Descendants([PersonalElectronics],
[Products].Levels(0)),[Qtr1] > 100.00))
Specifying UDAs in Formulas in Aggregate Storage Outlines
UDAs are words or phrases that you create for a member. For example, in Sample.Basic, top-level members of the Market dimension have the UDA Small Market or the UDA Major Market.
The Major Market example used in this topic shows how to create a formula for a member that shows the sum of sales for all major market members. The example assumes that a new member (Major Market Total) has been added to Sample.Basic.
-
MDX provides a Boolean function, IsUDA, which Returns TRUE if a member has the associated UDA tag. The following syntax returns TRUE if the current member of the Market dimension has the UDA “Major Market”:
IsUda([Market].CurrentMember, "Major Market")
-
A Filter function, when used with IsUDA (as shown in the following syntax), cycles through each member of the Market dimension and returns a value for each member that has the Major Market UDA:
Filter([Market].Members, IsUda([Market].CurrentMember, "Major Market"))
-
The Sum function adds the values returned by the Filter function; for the Major Market example, the following formula is produced:
Sum (Filter([Market].Members, IsUda([Market].CurrentMember, "Major Market")))
This formula is attached to the Major Market Total member.