Skip to main content Skip to complementary content

week - script and chart function

This function returns an integer representing the week number according to ISO 8601. The week number is calculated from the date interpretation of the expression, according to the standard number interpretation.


week(timestamp [, first_week_day [, broken_weeks [, reference_day]]])

Example diagram of week() function, with broken weeks

Diagram showing how the week function breaks up dates within the first month of the year, applying the default broken weeks system.

The week number count begins on January 1 (this is because Qlik Sense is set by default to use broken weeks). The first week ends on the day prior to the FirstWeekDay system variable regardless of how many days have occurred in that week. The FirstWeekDay system variable can be superseded within the week() function by the first_week_day argument.

Example diagram of week() function, with unbroken weeks and ReferenceDay=0

Diagram showing how the week function breaks up dates within the first month of the year, without applying the broken weeks system. In this example, the ReferenceDay parameter is also given a value of 0.

The week() function also provides the ability to specify whether to use broken or unbroken weeks via the broken_weeks argument. If the broken week functionality is employed, week 1 must contain a certain number of days in January as defined by the ReferenceDay system variable. Therefore, week 1 can potentially begin in December, or alternatively, weeks 52 or 53 may continue into January. Finally, the reference_day argument allows the function to override the ReferenceDay system variable.

Unlike the weekname() function, the week() function does not return the year value as well. This allows for aggregations comparing weeks across years.

There are four arguments that can be used within this function.

This is the date to evaluate as a timestamp or expression resolving to a timestamp, to convert, for example '2012-10-12'.

If you don't specify first_week_day, the value of variable FirstWeekDay will be used as the first day of the week.

If you want to use another day as the first day of the week, set first_week_day to:

  • 0 for Monday
  • 1 for Tuesday
  • 2 for Wednesday
  • 3 for Thursday
  • 4 for Friday
  • 5 for Saturday
  • 6 for Sunday

The integer returned by the function will now use the first day of the week that you set with first_week_day.


If you don't specify broken_weeks, the value of variable BrokenWeeks will be used to define if weeks are broken or not.

By default Qlik Sense functions use unbroken weeks. This means that:

  • In some years, week 1 starts in December, and in other years, week 52 or 53 continues into January.
  • Week 1 always has at least 4 days in January.

The alternative is to use broken weeks.

  • Week 52 or 53 do not continue into January.
  • Week 1 starts on January 1 and is, in most cases, not a full week.

The following values can be used:

  • 0 (=use unbroken weeks)
  • 1 (= use broken weeks)


If you don't specify reference_day, the value of variable ReferenceDay will be used to define which day in January to set as reference day to define week 1. By default, Qlik Sense functions use 4 as the reference day. This means that week 1 must contain January 4, or put differently, that week 1 must always have at least 4 days in January.

The following values can be used to set a different reference day:

  • 1 (= January 1)
  • 2 (= January 2)
  • 3 (= January 3)
  • 4 (= January 4)
  • 5 (= January 5)
  • 6 (= January 6)
  • 7 (= January 7)


When to use it

The week() function is useful when you would like to compare aggregations by weeks. For example, it could be used if you would like to see the total sales of products by week. The week() function is chosen over weekname() when the user would like the calculation to not necessarily use the application’s BrokenWeeks, FirstWeekDay, or ReferenceDay system variables.

Additionally, the week() function is chosen when you would like to compare across multiple years. By using the week() function, the user is able to create their own combination of these variables to be used in instances when the function is used.

These dimensions can be created either in the load script by using the function to create a field in a Master Calendar table, or used directly in a chart as a calculated dimension.

Function examples
Example Result

week( '10/12/2012')

Returns 41.

week( '35648') Returns 32, because 35648 = 08/06/1997.
week('10/12/2012', 0, 1) Returns 42.

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.

Example 1 – Default system variables

Example 2 – first_week_day

Example 3 – unbroken_weeks

Example 4 – reference_day

Example 5 – Chart object example

Example 6 – 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!