Skip to main content Skip to complementary content

yearend - script and chart function

This function returns a value corresponding to a timestamp of the last millisecond of the last day of the year containing date. The default output format will be the DateFormat set in the script.

Syntax:  

YearEnd( date[, period_no[, first_month_of_year = 1]])

In other words, the yearend() function determines which year the date falls into. It then returns a timestamp, in date format, for the last millisecond of that year. The first month of the year is, by default, January. However, you can change which month is set as first by using the first_month_of_year argument in the yearend() function.

Information note The yearend() function does not consider the FirstMonthOfYear system variable. The year begins on January 1 unless the first_month_of_year argument is used to change it.

Diagram of yearend() function.

Diagram that shows how the yearend() function identifies a date and the end of the year in which it takes place.

The yearend() function is used as part of an expression when you want the calculation to use the fraction of the year that has not yet occurred. For example, if you want to calculate the total interest not yet incurred during the year.

Return data type: dual

Arguments
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.

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

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. For more information, see Modifying regional settings for apps and scripts.

Default regional settings in apps are based on the user profile. These regional format settings are not related to the language displayed in the Qlik Cloud user interface. Qlik Cloud will be displayed in the same language as the browser you are using.

If you are an app creator, you can set the default region for apps you create. For more information, see Setting your preferred regional settings for creating apps and scripts in Qlik Cloud Analytics.

Function examples
Example Result
yearend('10/19/2001') Returns 12/31/2001 23:59:59.
yearend('10/19/2001', -1) Returns 12/31/2000 23:59:59.
yearend('10/19/2001', 0, 4) Returns 03/31/2002 23:59:59.

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!