Row Calculations

If you are having trouble with Calculations, try referring to the Script Troubleshooting Guide.

The “Row Calculation” tool performs rows based calculation on the table.  Each row of the table is evaluated independently and the results returned to the table in that row.  An example of a row based calculation would be to calculate the moment magnitude from the Seismic Moment for every event.

Calculation can be performed on single values or on columns of values and the resulting output can be a numbers, Dates, points, strings (text) or ID’s or a single number or single date.  Input can be any columns or single values of numbers, text, ID’s or dates.

The Calculation tool uses a scripting language that is based on JavaScript.  A basic introduction to the scripting is provided Here

Configuring a Calculations

Select a table. Calculations are returned to this table.

  1. Select an appropriate filter.  As the calculations are row based, the filter has no effect on the result. Using a filter will speed up calculations by excluding some rows from the calculations.  Null values will be returned for rows excluded from by the filter.
  2. Select what the calculation will return. The distinction should be made between the calculation of a single number or date when compared to calculating a new column of values as these impacts on calculation scripting.
  3. Add inputs and link to source. Inputs may be columns from the selected table or variables from any source. The name specified for an input will be the name used in coding so it is advisable to keep them short but meaningful.  
    They must be valid JavaScript variable names.
  4. Validation that the calculation is working. This involves "Check Syntax" and viewing results in a viewer. (I would recommend using a table view.)

General method for configuring a calculation.

Configure a calculation to generate text for header and footer

1. select table.

2. select 'text' drop down column.

3. configure inputs.

4. return messages. (see figure below)


HTML text can be used for special text formatting.  For more information on using HTML, refer to Working with HTML.


Last edited: 08-02-2013

Row Calculation Example - How to configure a row calculation to display events date by month using texts.

1. *New Row Calculation

2. Select event table, select equation to generate Texts (select a filter if required).

3. Add event date as an input column and give it a appropriate name.

4. Write the script for this tool to get Month value out of event date and return it as text based on the value.


Note:

1. Line 1 is to define the variable which will be used in this tool.

2. DateValue.getMonth() is a build-in function which extract the month value out of date and return it as a number. for more build-in functions, please see Math Functions.

3. From line 2, the if statement will return the month text depending on the month value.

4. The ... in line 8 is not a valid expression in javascript, it is just an illustration here. The full code must be typed in for it to work.



Created with the Personal Edition of HelpNDoc: Full-featured Help generator