Home > Commands > Database > Edit Data > Define Field by Expression

Define Field by Expression

The Define Field by Expression command allows you to create a database field from an expression involving other fields in the current database. For example, if you have two fields giving the salary for 1991 and 1992, you could compute the average salary using the expression:

(Salary91+Salary92)/2

This command executes the expression and stores the resulting values in the database field. Beware, however, that the resulting field is static, not dynamic like a spreadsheet cell that is defined as a formula. The defined field will not be updated automatically if the input fields are modified. Note also that a database field of the character type may not be created or edited by use of the Define Field by Expression command.

The dialog box displayed by this command lets you select the field to define and lets you enter the defining expression.

Field to define is the field that will be overwritten with new values, the values from evaluating your expression. If the desired field in not in the list, click the New Field button to add it to the Data Dictionary (or unhide it in the current Project). The field to be defined may exist in the database or it may be a new field. If the field already exists, the new data will replace existing data in the field.

Click the New button add a field to the Data Dictionary (or unhide a field in the current Project).

Expression is evaluated and the result written to the field you have chosen. If the expression extends past the end of the first line, the cursor will automatically wrap to the next line. While you are in this field, you can press the F1 function key to display the expression help screen, which lists the database fields and operators that can be used in the expression.

Selection Expression limits the number of records that will be processed. Only records that meet the selection criterion will be processed. If the field being defined does not yet exist, the field value for unselected records will be set to a missing value. If the field already exists, the values in unselected records will not be altered. Clicking the image/selection_expression_button.gif button accesses the Retrieve Selection Expression dialog box. Pick a selection expression to retrieve by clicking its name in the list of selection expressions in the current Project. You will return to the preceding dialog box and the selection expression will appear in the Selection Expression box.

Description may be any descriptive phrase, including spaces, under which to save this library entry.