Skip to main content

weekname - script and chart function

This function returns a value showing the year and week number with an underlying numeric value corresponding to a timestamp of the first millisecond of the first day of the week containing date.

Syntax:  

WeekName(date[, period_no[,first_week_day]])

The weekname() function determines which week the date falls into and returns the week number and year of that week. The first day of the week is determined by the FirstWeekDay system variable. However, you can also change the first day of the week by using the first_week_day argument in the weekname() function.

By default, Qlik Sense applications use broken weeks (defined by the BrokenWeeks system variable) and therefore the week number count begins on the January 1 and ends on the day prior to the FirsWeekDay system variable regardless of how many days have occurred.

Diagram of weekname function.

Diagram that shows a range of years and weeks that the weekname function can be used to set.

However, if your application is using unbroken weeks, week 1 can begin in the previous year or in the first few days in January. This depends on how you use the ReferenceDay and FirstWeekDay system variables.

The weekname() function is useful for when you would like to compare aggregations by weeks.

For example, if you want to see the total sales of products by week. To maintain consistency with the BrokenWeeks system variable in the application, use weekname() instead of lunarweekname(). If the application is using unbroken weeks, week 1 may contain dates from December of the previous year or exclude dates in January of the current year. If the application is using broken weeks, week 1 may contain less than seven days.

Return data type: dual

Arguments
Argument Description
date The date to evaluate.
period_no shift is an integer, where the value 0 indicates the week which contains date. Negative values in shift indicate preceding weeks and positive values indicate succeeding weeks.
first_week_day

Specifies the day on which the week starts. If omitted, the value of variable FirstWeekDay is used.

FirstWeekDay

You can use the following values to set the day on which the week starts in the first_week_day argument:

first_week_day values
Day Value
Monday 0
Tuesday 1
Wednesday 2
Thursday 3
Friday 4
Saturday 5
Sunday 6

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 app regional settings.

Default regional settings in apps are based on a combination of identity provider settings, system settings, or browser settings. 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.

Function examples
Example Result
weekname('01/12/2013') Returns 2013/02.
weekname('01/12/2013', -1) Returns 2013/01.
weekname('01/12/2013', 0, 1) Returns 2013/02.

Example 1 – Date with no additional arguments

Example 2 – period_no

Example 3 – first_week_day

Example 4 – Chart object example

Example 5 – Scenario