Create a Math Field
A math field is a mathematical operation involving measures or other user defined fields.
To create a math field:
- Select Cross > Define Field. The Define Fields window displays.
- Click Math. The Math Field window displays.
Enter the following details:
Field Description Field Name Enter a name for the field. Create Field For Select the database table to create the field for. Formula Create the mathematical formula. You can either type the formula into the field, or you can use the buttons at the bottom to include the fields or available mathematical operators.
Use the codes (e.g. V1 and V2) to represent the fields in the formula.
Operators Click the buttons in the Operators section to add one of the mathematical operators to your formula (or simply type the operators into the Formula field).
To add one of the advanced mathematical operators, select it from the drop-down list and click Add.
The following advanced operators are available:
round Rounds values. ln Calculates logarithmic values base e. exp Calculates exponential values base e. sqrt Calculates the square root. nullaszero Converts a null value to zero. Other input values are not affected and are preserved. isnull Returns 1 if the input is null, otherwise returns 0. not Returns 1 if the value is 0, otherwise returns 0. Check When you have finished creating your formula, you can click Check to test that it is mathematically valid. Click OK.
Math Fields and Null Values
The default behaviour is that any mathematical operation involving an undefined value results in an undefined (null) value for the calculated unit record value of the user defined field.
For example, if a table has two numeric columns and you use a math user defined field to sum the values in these columns, then the tabulation engine sees a table that looks like this:
Col1 | Col2 | Math UDF Col1 + Col2 |
---|---|---|
1 | 1 | 2 |
1 | Null | Null |
When tabulated and summed the columns display as:
Col1 | Col2 | Math UDF Col1 + Col2 |
---|---|---|
2 | 1 | 2 |
You can use the nullaszero, isnull, and not operators to detect and handle null values in a math field.