Skip to main content Skip to complementary content

weekyear - script and chart function

This function returns the year to which the week number belongs according to ISO 8601. The week number ranges between 1 and approximately 52.

Syntax:  

weekyear(expression)

Return data type: integer

The weekyear() function determines which week of a year a date falls into. It then returns the year corresponding to that week number.

By default, Qlik apps use broken weeks (defined by the BrokenWeeks system variable) and week number 1 begins on January 1 and the year ends after week 52. Therefore, the weekyear() function will always return the same value as the week() function when the application uses broken weeks.

Diagram of weekyear() function's range

Diagram that shows the range of time that the weekyear() function evaluates. The weekyear() identifies the year that a week number took place in.

However, if the BrokenWeeks system variable is set to use unbroken weeks, week 1 must only contain a certain number of days in January based on the value specified in the ReferenceDay system variable.

For example, if a ReferenceDay value of 4 is used, week 1 must include at least four days in January. It is possible for week 1 to include dates in December of the previous year or for the final week number of a year to include dates in January of the following year. In situations like this, the weekyear() function will return a different value to the year() function.

Diagram of weekyear() function's range when using unbroken weeks

Diagram that shows how the weekyear() function works with unbroken weeks. If unbroken weeks are used, the weekyear() function will return a different value than the year() function.

The weekyear() function is useful when you would like to compare aggregations by years. For example, if you would like to see the total sales of products by year. The weekyear() function is chosen over year() when the user would like to retain consistency with the BrokenWeeks system variable in the app.

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
weekyear('12/30/1996') Returns 1997, because week 1 of 1997 starts on 12/30/1996
weekyear('01/02/1997') Returns 1997
weekyear('12/28/1997') Returns 1997
weekyear('12/30/1997') Returns 1998, because week 1 of 1998 starts on 12/29/1997
weekyear('01/02/1999') Returns 1998, because week 53 of 1998 ends on 01/03/1999
Related topics
Topic Interaction
week - script and chart function Returns an integer representing the week number according to ISO 8601
year - script and chart function Returns an integer representing the year when the expression is interpreted as a date according to the standard number interpretation.

Example 1 - Broken weeks

Example 2 - Unbroken weeks

Example 3 - Chart object example

Example 4 - 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!