Return to last viewed topic Go to previous topic Go to next topic
Send us documentation feedback Technical support Learning Center Print topic

Using the Data Designer


Calculated Field ( )

Use a calculated field to perform a calculation based on values in other fields. For example, if your screen collects mortgage information, you could create one field to collect the mortgage and interest payment and another to collect taxes and insurance. The calculated field could sum those two numbers and display the monthly payment.

You can validate a calculated field. For example, you can require a positive number between 100 and 1,000.

Calculated fields are display only -- users cannot edit them.


Important!

If a field will be referenced in a calculation, use the validation feature to require a value for that field. This forces the user to enter a number to be used in the calculation.


Dialog Box

Fields on the Calculated Field Dialog

Field
Description
Name
Enter the name of the field.
Note that you cannot enter spaces nor most special characters (!@#$%^&*()+=<>,.:;'"{}[]\|`~) into this field.
Indexed
Check if you want to index this field. For more information, see "Indexing the Fields of a Data Design Document" in the Supporting the Data Designer chapter of the Developer Reference Guide.
The Indexed field may or may not appear, depending on how your administrator has set up your system.
Display name
Enter the text that appears when a user hovers the cursor over this field.
Calculation
Use this area of the screen to define the calculation that this field will perform.
Formula
Enter the calculation that this field will perform. See Also: Using the Formula Field
Select Field
Click this button to select a field to reference in the calculation. For more information, see Using the Formula Field.
Examples
Click the down arrow to the right of this field to see examples of calculations you can perform. When you select an example, it is copied into the Formula field.


Your system administrator can customize the examples. Instructions are provided in "The <cmddsgcalc> Command" in the Data Designer chapter of the Developer Reference Guide.

Validation
Select the kind of validation to apply to this field. Your choices are:
  • No validation - the user's response is not checked
  • Non-negative number (required) - the result of the calculation must be a positive number
  • Custom - You can create custom validation. For more information, see Custom Validation.
If you assign to this field any value other than No validation, the field is surrounded by red dashes in Data Entry mode. If the user's response does not meet the validation criteria, the field remains surrounded by red dashes. Your system administrator determines if a user can save a screen with invalid data.
Caption
Enter text to describe this item on the data entry screen.
After you insert this field onto the screen, you can use eWebEditPro+XML's formatting capabilities to modify its size, font, color, and other attributes.


Note: The Caption field only appears on this dialog when you create the Calculated field. If you later try to edit the field, the Caption field is not on the dialog. However, you can edit the Caption text within the editor.

Data Style

Using the Formula Field

You can copy a sample calculation into the Formula field by clicking the Examples field and selecting an operation from the drop down list. For example, if you click on Examples Add two numbers (X+Y), {X}+{Y} appears in this field.

Next, replace the variables with fields on the screen. Be sure to select the curly brackets ({}) as well as the letter between them. Then, when the user enters data into those fields, the calculation is performed using the current field values.

If a calculated field tries to perform a numerical calculation with a value that is blank or contains letters, NaN appears in the field. (NaN stands for "not a number.")

If a calculated field tries to divide by zero, Infinity appears.


Warning!

If the user does not replace all variables with a field or a number, when the content is validated, validation will fail.


To do this, follow these steps.

  1. Select the first variable to replace. To continue the example, select {X}.
  2. Click the Select Field button. A screen appears listing appropriate fields on the Data Design screen.

  1. Select a field to replace {X}. When you do, the field name replaces {X} in the Formula field.


Warning!

If a variable appears more than once in a formula (for example, {X} * number( {X} &lt;= {Y} ) + {Y} * number( {X} &gt; {Y}), you only need to replace the first occurrence it - eWebEditPro+XML will replace the subsequent occurrences for you.


  1. Continue replacing all variables in the formula.

Notes

- When using the XPath functions sum() and count(), all values with the field name are considered. For example, a document includes three books whose prices are $10, $20 and $30. In this case, sum's value is $60.

- When using all other functions, the first value is used. For example, a document includes three books whose prices are $10, $20 and $30. If a calculation formula refers to <price>, its value is $10.

Referencing Other Calculated Fields

A calculated field can only reference other calculated fields that appear before it in a document. For example, a document collects a series of numbers.

In this example, you must place the third field below or to the right of the first two fields. Calculated fields that are defined later in a document do not appear in the Select Field or Group dialog.

Explanation of Examples

The following table explains the standard examples that appear in the Examples drop-down list of the Calculated Field dialog. Note that your system administrator can customize the list, so it may not match what is below.

Example Field Text
Example Field Formula
Description
Add two numbers
{X} + {Y}
Add the value in the first field (X) to the value in the second field (Y).
Subtract two numbers
{X} - {Y}
Subtract the value in the second field (Y) from the value in the first field (X).
Multiply two numbers
{X} * {Y}
Multiply the value in the first field (X) by the value in the second field (Y).
Divide two numbers
format-number( {X} div {Y} ,'0.###')
Divide the value in the first field (X) by the value in the second field (Y).
Format as a percentage
format-number({X} div {Y} ,'#0%')
Determine what percentage one number (X) is of another (Y).
For example, if {X}=10 and {Y}=100, the result of the calculation is 10%.
Absolute value of a number
{X} * (number({X} &gt; 0)*2-1)
The number regardless of the sign (negative or positive).
Minimum of two numbers
{X} * number( {X} &lt;= {Y} ) + {Y} * number( {X} &gt; {Y})
The smaller of two field values.
Maximum of two numbers
{X} * number( {X} &gt;= {Y} ) + {Y} * number( {X} &lt; {Y})
The larger of two field values.
Zero if subtraction is negative
({X} - {Y}) * number(({X} - {Y}) &gt; 0)
Subtract one number (Y) from another (X). If the difference is less than zero, insert zero.
Multiply by another number if checkbox is checked
{X} * ( {Y} * number( {Z} ='true') + number( {Z} !='true'))
X is a numeric field.
Y is another numeric field to multiply by X if a checkbox is checked.
Z is the checkbox.
For example, {X}=2 and {Y}=3
  • if the checkbox is checked, the result is 2 * 3, which is 6
  • If the checkbox is not checked, the result is 2
Round a decimal number
round({X})
Rounds the number to the nearest integer. For example, round(3.14). The result is 3.
Round up a decimal number
ceiling({X})
Returns the smallest integer that is greater than the number. For example, ceiling(3.14). The result is 4.
For negative numbers:
ceiling(-3.14) = -3
Round down a decimal number
floor({X})
Returns the largest integer that is not greater than the number argument. . For example, floor(3.14). The result is 3.
For negative numbers:
floor(-3.14) = -4
Format decimal number 0.00
format-number( {X} ,'0.00')
Rounds a value either up or down to the hundredth place. As examples, 100 becomes 100.00, and 3.14159265 becomes 3.14.
Total numeric values from multiple fields
sum( {X}[text()] | {Y}[text()] | {Z}[text()] ))
Add the values in all referenced fields.
Only elements that contain a value are summed. Empty elements are excluded.
Total a list of numeric values
sum( {X}[text()] )
Total all values in a single repeating field. Here's an example.
Plain Text Field properties
Name: Miles
Allow: more than one
Validation: non-negative whole number
XML Data
<root>
<Miles>89</Miles>
<Miles>12</Miles>
<Miles>23</Miles>
<Miles>19</Miles>
</root>
sum(Miles) equals 89+12+23+19=143
Only elements that contain a value are summed. Empty elements are excluded.
Average a list of numeric values
format-number(sum( {X}[text()] ) div count( {X} ),'0.###')
Calculate the average of all values in a single repeating field.
To continue the example from the Total a list of numeric values field (above):
Plain Text Field properties
Name: Miles
Allow: more than one
Validation: non-negative whole number
XML Data
<root>
<Miles>89</Miles>
<Miles>12</Miles>
<Miles>23</Miles>
<Miles>19</Miles>
</root>
Average=89+12+23+19=143
divided by the number of values (4)= 35.75
Only elements that contain a value are summed. Empty elements are excluded.
Count the number of values in a list
count( {X} )
Calculate the number of values in a single repeating field.
To continue the example from the Total a list of numeric values field (above):
Plain Text Field properties
Name: Miles
Allow: more than one
Validation: non-negative whole number
XML Data
<root>
<Miles>89</Miles>
<Miles>12</Miles>
<Miles>23</Miles>
<Miles>19</Miles>
</root>
Count = 4
Lowercase text
translate( {X} ,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')
Replace all uppercase characters with the lowercase version of that character
Uppercase text
translate( {X} ,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')
Replace all lowercase characters with the uppercase version of that character
Remove extra spaces
normalize-space( {X} )
Remove extra space characters from content\
Concatenate text
concat( {X} , ', ' , {Y} )
Link text strings together into a single string. For example, concat('The',' ','XML') yields The XML.
Size of a text string
string-length( {X} )
Count the number of characters in a selected field's value. For example, if the referenced field's value is Hello, string-length = 5.


Send us documentation feedback Technical support Learning Center Print topic Return to last viewed topic Go to previous topic Go to next topic