Skip to main content

Derived fields

If you have a group of fields that are related, or if fields carry information that can be broken up into smaller parts that are relevant when creating dimensions or measures, you can create field definitions that can be used to generate derived fields. One example is a date field, from which you can derive several attributes, such as year, month, week number, or day name. All these attributes can be calculated in a dimension expression using Qlik Sense date functions, but an alternative is to create a calendar definition that is common for all fields of date type. Field definitions are stored in the data load script.

You use the Declare statement to create a definition of the derived fields. This is where you define the different attributes of the field, in this case date related attributes.

Calendar: DECLARE FIELD DEFINITION TAGGED '$date' Parameters first_month_of_year = 1 Fields Year($1) As Year Tagged '$year', Month($1) as Month Tagged '$month', Date($1) as Date Tagged ('$date', '$day'), Week($1) as Week Tagged '$week', Weekday($1) as Weekday Tagged '$weekday', DayNumberOfYear($1, first_month_of_year) as DayNumberOfYear Tagged ('$numeric');
 

See: Declare

The next step is to use the Derive statement to map existing data fields to the calendar. This will create the derived fields. You can do this in three ways:

  • Map specific fields by field name.

    DERIVE FIELDS FROM FIELDS OrderDate,ShippingDate USING Calendar;
  • Map all fields with one or more specific field tags.

    DERIVE FIELDS FROM EXPLICIT TAGS '$date' USING Calendar;
  • Map all fields that are tagged with one of the tags of the field definition ($date in the example above).

    DERIVE FIELDS FROM IMPLICIT TAG USING Calendar;

See: Derive

Qlik Sense is prepared to recognize derived date fields if you have created a calendar definition and mapped the fields like in the example here. They are available in the Date & time fields section of the Fields asset panel. You will also find all derived fields in the expression editor and when you create or edit dimensions.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!