Developing Calculation Scripts:: Understanding Calculation Scripts

A calculation script, which contains a series of calculation commands, equations, and formulas, allows you to define calculations other than those defined by the database outline. In a calculation script, you can perform a default calculation (CALC ALL) or a calculation of your choosing (for example, you can calculate part of a database or copy data values between members). You must write a calculation script to do any of the following tasks: • • • Calculate a subset of a database. Change the calculation order of the dense and sparse dimensions in a database. Perform a complex calculation in a specific order or perform a calculation that requires multiple iterations through the data (for example, some two-pass calculations require a calculation script) Perform any two-pass calculation on a dimension without an accounts tag. Perform a currency conversionSee Designing and Building Currency Conversion Applications. Calculate member formulas that differ from formulas in the database outline (formulas in a calculation script override formulas in the database outline) Use an API interface to create a custom calculation dynamically Use control of flow logic in a calculation (for example, to use the IF…ELSE…ENDIF or the LOOP…ENDLOOP commands) Clear or copy data from specific membersSee Copying Data. Define temporary variables for use in a database calculationSee Declaring Data Variables. Force a recalculation of data blocks after you have changed a formula or an accounts property on the database outline Control how Essbase uses Intelligent Calculation when calculating a databaseSee Understanding Intelligent Calculation. Ex:: FIX (Actual) CALC DIM(Year, Measures, Market, Product); ENDFIX

• •
• •

• •

Rules for Calculation Script Syntax::
 End each formula or calculation script command with a semicolon (;): Example 1: CALC DIM(Product, Measures);

hyphen ( . for example. 2. If a member name begins with &. "Opening Inventory" = "Ending Inventory" .. Example 4: IF (Sales <> #MISSING) Commission = Sales * .9. EXCLUDE. If you are using an IF statement that is nested within another IF statement. You do not need to end the following commands with semicolons: IF. ENDLOOP Note: Although not required. ENDFIX. ELSE. Do not enclose substitution variables in quotation marks in a calculation script. for example.100. Example 3: "Market Share" = Sales % Sales -> Market.  If you are using an IF statement or an interdependent formula. The leading ampersand (&) is reserved for substitution variables. the previous formula contains a simple IF.Sales + Additions.  Enclose a member name in double quotation marks (" "). Contains only numerals or starts with a numeral. 5. ELSE Commission = #MISSING.Example 2: DATACOPY Plan TO Revised_Plan. 1999. Includes any nonalphanumeric character. Contains spaces. FIX. enclose it in quotation marks. Begins with an ampersand (&).). “100” or “10Prod”. enclose the formula in parentheses to associate it with the specified member. asterisk ( * ).). end each IF . if that member name meets any of the following conditions: 1. or slash ( / ). ENDEXCLUDE. For example.)  End each IF statement in a formula with an ENDIF statement. it is good practice to follow each ENDIF statement in a formula with a semicolon. For example. the following formula is associated with the Commission member in the database outline: Commission (IF(Sales < 100) Commission = 0. ENDIF. 4. 3..ENDIF. ELSIF. LOOP.Jan or . for example. Contains a dot (.ENDIF statement. ENDIF.

ELSE Marketing = Marketing * 1. CALC FIRST.with an ENDIF statement.@DESCENDANTS(East)) CALC DIM(Year.5. ENDFIX  End each EXCLUDE statement with an ENDEXCLUDE statement.)  You do not need to end ELSE or ELSEIF statements with ENDIF statements. . ELSE "Opening Inventory" = @PRIOR("Ending Inventory"). For example: FIX(Budget. Measures.9. For example: Marketing (IF (@ISMBR(@DESCENDANTS(West)) OR @ISMBR(@DESCENDANTS(East))) Marketing = Marketing * 1. CALC AVERAGE.)  End each FIX statement with an ENDFIX statement. membername. ELSEIF(@ISMBR(@DESCENDANTS(South))) Marketing = Marketing * . ENDIF. CALC LAST. CCONV. Product). ENDIF. Understanding Calculation Commands List of Commands for Calculating a Database CALC ALL. CALC DIM. Controlling the Flow of Calculations Calculate a subset of a database by inclusion Calculate a subset of a database by exclusion Specify the number of times that commands are iterated FIX…ENDFIX EXCLUDE… ENDEXCLUDE LOOP…ENDLOOP can also use the IF and ENDIF commands to specify conditional calculations.1. ENDIF. For example: "Opening Inventory" (IF (@ISMBR(Budget)) IF (@ISMBR(Jan)) "Opening Inventory" = Jan. CALC TWOPASS.

# (pound sign). SET CACHE. SET CALCTASKDIMS. CREATEONMISSINGBLK. For example: /* This calculation script comment spans two lines. */ . SET CREATEBLOCKEQ. if the Scenario dimension has four members. Adding Comments You can include comments to annotate calculation scripts. SET LOCKBLOCK. FRMLBOTTOMUP. SET UPDATECALC. For example. SET CALCPARALLEL. and _ (underscore) Typically.Declaring Data Variables List of Commands for Declaring Data Variables Calculation Declare one-dimensional array variables Declare a temporary variable that contains a single value Comma nd ARRAY VAR Values stored in temporary variables exist only while the calculation script is running. To include a comment. arrays are used to store variables as part of a member formula. the following command creates an array called Discount with four entries: ARRAY Discount[Scenario]. Specifying Global Calculation Settings for a Database SET SET SET SET AGGMISSG. Essbase ignores these comments when it runs the calculation script. The size of the array variable is determined by the number of members in the corresponding dimension. You cannot report on the values of temporary variables. SET MSG (SET NOTICE). You can use multiple arrays at a time. CLEARUPDATESTATUS. start the comment with /* and end the comment with */. Variable and array names are character strings that contain any of the following characters: • • • Letters a–z Numerals 0–9 Special characters: $ (dollar sign). SETUPTOLOCAL.

Planning Calculation Script Strategy You can enter a calculation script directly into the text area of Calculation Script Editor. and mathematical expression is any valid mathematical expression. use the member name followed by a semicolon (. Expenses = Payroll + Marketing + Misc. For example. See Developing Formulas. the following command calculates the formula applied to the Variance member in the database outline: Variance. the formula overrides conflicting formulas that are applied to members in the database outline. adding the values in the members Payroll. Marketing. Using Formulas in a Calculation Script You can place member formulas in a calculation script. subtracting the values in COGS from the values in Sales and placing the result in Margin: Margin = Sales . the following formula causes Essbase to cycle through the database. and placing the result in the Expenses member. or you can use the UI features of Calculation Script Editor to build the calculation script. The next formula cycles through the database subtracting the values in Cost from the values in Retail. When you do.COGS. To override values that result from calculating an outline. and Misc.). Basic Equations Member = mathematical expression. In a calculation script. the following formula cycles through the database. Note: You cannot apply formulas to shared members or label only members. Member is a member name from the database outline. . Essbase evaluates the expression and assigns the value to the specified member. you can perform both of these operations: • • Calculate a member formula on the database outline Define a formula To calculate a formula that is applied to a member in the database outline. For example. manually apply a formula that you define in a calculation script. This formula overrides any formula placed on the Expenses member in the database outline. For example. calculating the resulting values as a percentage of the values in Retail.

You can also use the > (greater than) and < (less than) logical operators in equations. if false.Cost) % Retail. Sales Increase Flag results in a 1 value. In the following example. if it is true that February sales are greater than January sales.and placing the results in Markup: Markup = (Retail . . the result is a 0 value: Sales Increase Flag = Sales -> Feb > Sales -> Jan.

Sign up to vote on this title
UsefulNot useful