Skip to main content Skip to complementary content

yearname - script and chart function

This function returns a four-digit year as display value with an underlying numeric value corresponding to a timestamp of the first millisecond of the first day of the year containing date.

Diagram of range of time of the yearname() function.

Diagram that shows the range of time in which the yearname function will return a result.

The yearname() function is different to the year() function as it lets you offset the date you want evaluated and lets you set the first month of the year.

If the first month of the year is not January, the function will return the two four-digit years across the twelve month period that contain the date. For example, if the start of the year is April and the date being evaluated is 06/30/2020, the result returned would be 2020-2021.

Diagram of yearname() function with April set as the first month of the year.

Diagram that shows that the yearname function can identify dates within a twelve month period and that its return can depend on which month is set as the first month of the year.

Syntax:  

YearName(date[, period_no[, first_month_of_year]] )

Return data type: dual

Argument Description
date The date or timestamp to evaluate.
period_no period_no is an integer, where the value 0 indicates the year which contains date. Negative values in period_no indicate preceding years and positive values indicate succeeding years.
first_month_of_year If you want to work with (fiscal) years not starting in January, indicate a value between 2 and 12 in first_month_of_year. The display value will then be a string showing two years.

You can use the following values to set the first month of year in the first_month_of_year argument:

first_month_of_year values
Month Value
February 2
March 3
April 4
May 5
June 6
July 7
August 8
September 9
October 10
November 11
December 12

The yearname() function is useful for comparing aggregations by year. For example, if you want to see the total sales of products by year.

These dimensions can be created in the load script by using the function to create a field in a Master Calendar table. They can also be created in a chart as calculated dimensions

Regional settings

Unless otherwise specified, the examples in this topic use the following date format: MM/DD/YYYY. The date format is specified in the SET DateFormat statement in your data load script. The default date formatting may be different in your system, due to your regional settings and other factors. You can change the formats in the examples below to suit your requirements. Or you can change the formats in your load script to match these examples.

Default regional settings in apps are based on the regional system settings of the computer or server where Qlik Sense is installed. If the Qlik Sense server you are accessing is set to Sweden, the Data load editor will use Swedish regional settings for dates, time, and currency. These regional format settings are not related to the language displayed in the Qlik Sense user interface. Qlik Sense will be displayed in the same language as the browser you are using.

Function examples
Example Result
yearname('10/19/2001') Returns '2001.'
yearname('10/19/2001',-1) Returns '2000.'
yearname('10/19/2001',0,4) Returns '2001-2002.'
Related topics
Topic Description
year - script and chart function This function returns an integer representing the year when the expression is interpreted as a date according to the standard number interpretation.

Example 1 – No additional arguments

Example 2 – period_no

Example 3 – first_month_of_year

Example 4 – Chart object example

Example 5 – Scenario

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!