This article will cover the syntax of the ‘derive’ regular script statement.
The derive statement is used to generate fields using definitions created in the ‘declare’ statement.
Statement syntax
Fields can be specified by name:
Derive Field | Fields
From Field | Fields [field_list]
Using Definition_name
Alternatively, they can be specified by tags:
Derive Field | Fields
From Explicit | Implicit
Tag | Tags [tag_list]
Using Definition_name
Definition_name | This is the name of the definition that is to be used to derive the field. |
Field_list | This is a comma separated list of fields from which the new fields will be generated. The field list is only specified if the fields are being generated from specific fields instead of tags. |
Explicit | Implicit | When using tags to derive fields, you must specify whether these are explicit or implicit tags. Using explicit you can specify exact tags you wish to derive new fields for. Using implicit you cannot specify tags. Instead, all fields that have the same tag as the definition will be used to generate new fields. |
Tag_list | This is a list of tags you want to derive fields based on when using the explicit clause. |
Example
This example creates field definitions that create a calendar when used with a date field. The new fields are then derived using the specific field name.
DATES:
Load * inline [
dataDate
01/01/2022
01/02/2022
01/03/2022
];
CALENDAR_DEFINITIONS:
DECLARE FIELD DEFINITION TAGGED '$date'
Fields
Year($1) as Year Tagged ('$numeric'),
Month($1) as Month Tagged ('$numeric'),
Date($1) as Date Tagged ('$date'),
Week($1) as Week Tagged ('$numeric');
DERIVE FIELDS FROM FIELDS dataDate USING CALENDAR_DEFINITIONS;
See this article for the code to our ultimate derived calendar.
Result
The field ‘dataDate’ is loaded into the app in the table ‘DATES’. In addition, 4 fields are created as specified by the definition.