Enhancing Reports using Formulas and Variables

Objective

After completing this lesson, you will be able to implement formulas and variables

Formulas

Watch this video to learn about the Formulas.

Variables

A variable is a formula that you save with a name. A qualification is assigned to the variable, which is based on the formula. A variable acts as an object in the document and displays in the Document Dictionary tab in the Main Side Panel, similar to any other data object. You can use the variable as you would use any object to display the results of the calculation in multiple blocks and reports throughout the Web Intelligence document.

The advantage of creating a variable is that you can reuse the formula without having to enter it each time. A variable is defined according to the formula you enter when you create it. However, a variable behaves like a standard object in a query and a document.

A variable is saved in a document. Therefore, it can be used in any report within the document.

Considering the advantages of a variable, create a variable instead of a formula. When required, you can create a formula and later convert it to a variable, but creating a variable directly saves you time and effort.

Variables are useful when you require a calculation and plan to use it more than once and in different blocks and report tab pages within a document.

Variables: 1: Choose Document Dictionary tab. 2: Choose Add a New Variable. 3: In the Name field, enter Net revenue for example. 4: Open the Qualification list. 5: Select Measure for example.

Functions

A custom calculation sometimes contains only report objects, for example [Sales Revenue] / [Number of Sales]. Calculations can also include functions in addition to report objects.

A function receives zero or more values as input and returns output based on those values.

For example, the Sum function totals all the values in a measure and outputs the result. The formula Sum([Sales Revenue]) outputs a total of sales revenues. In this case, the function input is the Sales Revenue measure and the output is the total of all Sales Measures.

Including functions in cells

The text in report cells always begins with the = sign .

Literal text appears in quotation marks, while formulas appear without quotation marks.

For example, the formula Average([Revenue]) appears in a cell as =Average([Revenue]). The text Average Revenue? appears as ="Average Revenue?".

You can use text alone in a cell, or mix formulas and text by using the + operator.

If you want a cell to display the average revenue preceded by the text "Average Revenue:", the cell text is as follows: ="Average Revenue: " + Average([Revenue]).

Note the space at the end of the text string so that the text and the value are not placed directly side-by-side in the cell.

Function Syntax

The Formula Editor displays the function syntax when you select the function.

To use a function you need to know its name, how many input values it requires and the data types of these input values. You also need to know the type of data that the function outputs.

For example, the Sum function takes a numerical object as input (for example a measure showing sales revenue) and outputs numeric data (the sum of all the values of the measure object).

Here is the syntax of the Abs function: num Abs(number).

This syntax tells you that the Abs function takes a single number as input and returns a number as output.

Examples of Functions

You have a report showing Year, Quarter and Sales revenue. The State object also appears in the report data, although it is not displayed. When the user runs the report, they are presented with a prompt and they must choose a state. You want to show the state that they have chosen in the report title. The text in the prompt is "Choose a State:".

Screen capture: Example. See text before image for more details.

Function: UserReponse

  • To respond to the request, we will use the UserResponse function:
    • Description: Returns the response to a prompt
    • Function Group: Data Provider
    • Syntax: string UserResponse([dp;]prompt_string[;Index])
  • Finally, we will use this function in a new formula:
    • Type: Formula
    • Syntax: ="Quarterly Revenues for " + UserResponse("Choose a State")

The UserResponse function includes several parameters:

ParameterDescriptionTypeRequired
dpThe data providerData providerNo
prompt_stringThe prompt textStringYes
IndexTells the function to return the database primary keys of the prompt valuesKeywordNo

Create and Modify Variables

Log in to track your progress & complete quizzes