In this section: |
When you create content, you are not restricted to the fields that exist directly in your data source. You can add calculations to automate summations and other mathematical tasks related to your data fields. You can specify operators, fields, variables, and functions when creating a calculation. If you can generate the information you want from the existing data, you can create a temporary field to evaluate and display it. A temporary field is a field whose value is not stored in the data source, but can be calculated from the data that is there. A temporary field takes up no storage space in the data source, and is created only when needed.
You can create two types of temporary fields, which differ in how they are evaluated:
How to: |
You can use the calculator to perform basic calculations on fields in your data hierarchy. When you create a calculated field, a new, unique field is created. It incorporates all of the data fields and expressions that you added to the calculation.
Once the calculation is complete, a new data field is created which can subsequently be used in your content. This field is placed on the Data pane, using the label of the originating field on which you created the initial calculation. For example, you can perform an addition operation on two fields. This action sums the values of the fields, displaying the total of the two when the field is used in a chart. You can also perform more advanced calculations that can result in different outcomes.
Calculated fields include DEFINEs, COMPUTEs, quick transforms, and more. You also have access to WebFOCUS functions that can be used in a calculation to perform specific operations on character and numeric fields. These display in a list of available functions . They are separated into categories, listed in alphabetical order, and are case-insensitive.
A DEFINE field is evaluated before data aggregation, while a COMPUTE field is evaluated after data aggregation. This means that DEFINE fields are especially useful to sort the data in a chart or report, while a COMPUTE field is especially useful as a measure field.
You can determine whether a calculation will be created as a DEFINE or COMPUTE by selecting Calculate at the source or Calculate after aggregation in the calculator. When you select Calculate at the source, a DEFINE field is created, and when you select Calculate after aggregation, a COMPUTE field is created. When you create a DEFINE field, it is added to the field list, from where you can add it to your content. When you create a COMPUTE field, it is added to your content automatically, in the default measure bucket if it was created from the field list, or in the bucket from where you created the COMPUTE.
Access the calculation feature in one of the following ways:
When you perform one of these actions, the calculator opens, as shown in the following image.
The following considerations apply to Field/Function/Variable lists.
You can still use a function, even if it is not listed, by typing it into the calculator canvas. See the Using Functions technical content for a complete list of available functions, including legacy functions.
A DEFINE is a virtual field that is evaluated as each record that meets the selection criteria is retrieved from the data source. The result of the expression is treated as though it were a real field stored in the data source. It is added to the field list in the Resources panel, from which you can add it to multiple content items.
You can use a WebFOCUS function in a DEFINE or in a COMPUTE to transform data from an existing field to create a new field. Each function accepts a different set of arguments that are added in parentheses after the function name.
DEFINEs are built from the field list in the Resources panel.
DEFINEs can be created in the following ways:
In this example, a new DEFINE field will be created that uses the DTRUNC function to supply the first day of the week for each sale date.
The calculator opens to create a new DEFINE field, by default. Notice that the Create at the source radio button is selected.
The Function list appears, and displays the first available function category.
Note: If you create the new calculation by right-clicking a field, that field is automatically added to the calculator text area. For the present example, delete this text before continuing.
Double-click the DTRUNC function, or drag it into the Calculator text area.
The text area displays the function and identifies the required arguments, in this case, date and period. Notice that an example is provided in the space below the calculator text area.
Click the Fields tab to access the Field list. Under Dimensions, expand Sales_Related, Transaction Date, Simple, Sale,Day, and Sale Date Details, then double-click Sale,Date.
The Sale Date field is added as the first argument in the DTRUNC function, as shown in the following image.
DTRUNC("Sale,Date", WEEK)
Click the Edit format button, change the Data type to a date format, and select an option of your choice from the Date format drop-down menu.
Click OK.
If the validation indicated that there was an error, determine the cause of the issue and fix it.
If you created the DEFINE by right-clicking a field in the Field panel, it displays at the bottom of the measure or dimension group where it was created from. If you have trouble locating your calculated field, type the name into the search box to find it.
You can use the calculated field from this example to create a chart or report that shows sales information for each week, as shown in the following image.
COMPUTEs are calculated fields whose values are evaluated after all of the data that meets the selection criteria is retrieved, sorted, and summed. The calculation uses the aggregated (total) values of the fields. For example, based on the values of Revenue and MSRP fields in your data source, you could calculate the discount percentage.
Create a COMPUTE field by selecting Calculate after aggregation in the calculator.
Note: The field that you right-click to create the COMPUTE field is automatically added to the text area, as shown in the following image.
You can select another field, or add fields from the data source tree that display.
Note: For COMPUTEs, the Calculate after aggregation check box is selected, indicating that the field values are evaluated after the chart or report has been sorted.
1 - ("Revenue"/"MSRP")
The following image shows this expression in the Calculator.
Note: You can use the buttons in the Operator Selection area instead of typing some mathematical operators.
Click the Format icon to open the Format dialog box. Click the Percent Type option to change the field format to a percentage, as shown in the following image.
The percentage option automatically multiplies the values in the field by 100 to produce a percentage, so we do not need to perform this operation in the COMPUTE expression.
Double-click the field name next to the Format icon, and type a new name for the field.
Click the Field Properties menu, and type a column title for the field, as shown in the following image.
If the validation indicated that there was an error, determine the cause of the issue and fix it.
The field is added to the same bucket from which you created it. You can move it to a different bucket or delete the original field, Revenue, in this example, from which it was created.
The following image shows a data grid that displays the Revenue and the calculated Discount Percentage for different product models.
If you remove the COMPUTE field from your content, it is deleted permanently. COMPUTE fields are not stored in the Resources panel.
Once you have created a calculated field (DEFINE or COMPUTE), you can edit it. This allows you to revise the calculation and in the field so that you can achieve the results you expect.
Note: You cannot edit a calculated field that is already being used in a static or prompted filter. You may, however, delete the filter, edit the calculated field, then recreate the filter using the edited field.
WebFOCUS Designer opens.
The revised field displays in the location from which you edited it.