In this section: |
When you create a chart, you are not restricted to the fields that exist 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 (a virtual field and a calculated value), which differ in how they are evaluated:
In addition to creating DEFINE and COMPUTE temporary fields, you can use Quick Transforms to apply analytical functions, such as standard deviation and correlation, to measure fields in your chart. Quick Transform calculations are performed using the aggregated values of the fields to create post-aggregation (COMPUTE) fields.
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 chart. 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, Aggregations, and other calculated fields. 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 noting whether or not the Calculate after aggregation check box is selected. When selected, a COMPUTE is created. When cleared a DEFINE is created.
Access the Calculation feature in one of the following ways:
Using the calculator, you can create basic calculations, 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.
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 data pane.
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.
On the WebFOCUS Home Page, on the Designer tab, click Chart or Report. In the Open dialog box, navigate to and select wf_retail_lite.mas and click Select.
WebFOCUS Designer opens.
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 Date type to a date format, and select an option of your choice from the Date format drop-down menu.
Click OK.
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.
COMPUTE fields in a chart are built from fields that are located in the buckets. You can create a COMPUTE field in a report from a field in the report, or by clicking the menu next to the Rows bucket or the measure bucket.
On the WebFOCUS Home Page, on the Designer tab, click Chart or Report. In the Open dialog box, navigate to and select wf_retail_lite.mas and click Select.
WebFOCUS Designer opens.
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, by default, indicating that the field values are evaluated after the chart or report has been sorted. This check box is enabled for COMPUTE fields only.
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.
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 Field 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.
The revised field displays in the location from which you edited it.
|
WebFOCUS |