Early Access: The content on this website is provided for informational purposes only in connection with pre-General Availability Qlik Products. All content is subject to change and is provided without warranty.
This function returns the year to which the week number belongs according to the environment variables. The week number ranges between
1 and approximately 52.
Specifies the day on which the week starts. If omitted, the value of variableFirstWeekDay is used.
The possible values first_week_day are 0 for Monday, 1 for Tuesday, 2 for Wednesday, 3 for Thursday, 4 for Friday, 5 for Saturday, and 6 for Sunday.
For more information about the system variable, see FirstWeekDay.
broken_weeks
If you don't specify broken_weeks, the value of variable BrokenWeeks will be used to define if weeks are broken or not.
For more information about the system variable, see
BrokenWeeks
reference_day
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.
For more information about the system variable, see
ReferenceDay
The weekyear() function determines which week of a year a date falls into. It then returns the year corresponding to that week number.
If BrokenWeeks is set to 0 (false), weekyear() will return the same as year().
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.
When to use it
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. 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.
The weekyear() function, set as the field ‘week_year’ that returns the year in which the transactions took place.
The week() function, set as the field ‘week’ that shows the week number of each transaction date.
Load script
SET BrokenWeeks=1;
Transactions:
Load
*,
week(date) as week,
weekyear(date) as week_year
;
Load
*
Inline
[
id,date,amount
8176,12/28/2020,19.42
8177,12/29/2020,23.80
8178,12/30/2020,82.06
8179,12/31/2020,40.56
8180,01/01/2021,37.23
8181,01/02/2021,17.17
8182,01/03/2021,88.27
8183,01/04/2021,57.42
8184,01/05/2021,67.42
8185,01/06/2021,23.80
8186,01/07/2021,82.06
];
Results
Load the data and open a sheet. Create a new table and add these fields as dimensions:
id
date
week
week_year
Results table
id
date
week
week_year
8176
12/28/2020
53
2020
8177
12/29/2020
53
2020
8178
12/30/2020
53
2020
8179
12/31/2020
53
2020
8180
01/01/2021
1
2021
8181
01/02/2021
1
2021
8182
01/03/2021
2
2021
8183
01/04/2021
2
2021
8184
01/05/2021
2
2021
8185
01/06/2021
2
2021
8186
01/07/2021
2
2021
The ‘week_year’ field is created in the preceding load statement by using the weekyear() function and passing the date field as the function’s argument.
The BrokenWeeks system variable is set to 1 meaning that the app uses broken weeks. Week 1 begins on January 1.
Transaction 8181 takes place on January 2, which is part of week 1. Therefore, it returns a value of 2021 for the ‘week_year’ field.
Example 2 - Unbroken weeks
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
A dataset containing a set of transactions for the last week of 2020 and first week of 2021 which is loaded into a table called ‘Transactions’.
The BrokenWeeks variable which is set to 0.
A preceding load which contains the following:
The weekyear() function, set as the field ‘week_year’ that returns the year in which the transactions took place.
The week() function, set as the field ‘week’ that shows the week number of each transaction date.
However, in this example, the company policy is to use unbroken weeks.
Load script
SET BrokenWeeks=0;
Transactions:
Load
*,
week(date) as week,
weekyear(date) as week_year
;
Load
*
Inline
[
id,date,amount
8176,12/28/2020,19.42
8177,12/29/2020,23.80
8178,12/30/2020,82.06
8179,12/31/2020,40.56
8180,01/01/2021,37.23
8181,01/02/2021,17.17
8182,01/03/2021,88.27
8183,01/04/2021,57.42
8184,01/05/2021,67.42
8185,01/06/2021,23.80
8186,01/07/2021,82.06
];
Results
Load the data and open a sheet. Create a new table and add these fields as dimensions:
id
date
week
week_year
Results table
id
date
week
week_year
8176
12/28/2020
53
2020
8177
12/29/2020
53
2020
8178
12/30/2020
53
2020
8179
12/31/2020
53
2020
8180
01/01/2021
53
2020
8181
01/02/2021
53
2020
8182
01/03/2021
1
2021
8183
01/04/2021
1
2021
8184
01/05/2021
1
2021
8185
01/06/2021
1
2021
8186
01/07/2021
1
2021
The BrokenWeeks system variable is set to 0 meaning that the application uses unbroken weeks. Therefore, week 1 is not required to begin on January 1.
Week 53 of 2020 continues until the end of January 2, 2021, with week 1 of 2020 beginning on Sunday, January 3, 2021.
Transaction 8181 takes place on January 2, which is part of week 1. Therefore, it returns a value of 2021 for the ‘week_year’ field.
Example 3 - Chart object example
Overview
The same dataset and scenario as the first example are used.
However, in this example the dataset is unchanged and loaded into the application. The calculation that returns the week number of the year when the transactions took place is created as a measure in a chart in the app.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
id
date
To calculate the week that a transaction takes place in, create the following measure:
=week(date)
To calculate the year that a transaction takes place in based on the week number, create the following measure:
=weekyear(date)
Results table
id
date
week
week_year
8176
12/28/2020
53
2020
8177
12/29/2020
53
2020
8178
12/30/2020
53
2020
8179
12/31/2020
53
2020
8180
01/01/2021
1
2021
8181
01/02/2021
1
2021
8182
01/03/2021
2
2021
8183
01/04/2021
2
2021
8184
01/05/2021
2
2021
8185
01/06/2021
2
2021
8186
01/07/2021
2
2021
The ‘week_year’ field is created in the preceding load statement by using the weekyear() function and passing the date field as the function’s argument.
The BrokenWeeks system variable is set to 1 meaning that the app uses broken weeks. week 1 begins on January 1.
Transaction 8181 takes place on January 2, which is part of week 1. Therefore, it returns a value of 2021 for the ‘week_year’ field.
Example 4 - Scenario
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
A dataset containing a set of transactions for the last week of 2020 and first week of 2021 which is loaded into a table called ‘Transactions’.
The BrokenWeeks variable which is set to 0. This means the app will use unbroken weeks.
The ReferenceDay variable which is set to 2. This means the year will begin on January 2 and will contain a minimum of two days in January.
The FirstWeekDay variable which is set to 1. This means the first day of the week will be Tuesday.
The company policy is to use broken weeks. The end user would like a chart that presents the total sales by year. The app uses unbroken weeks with week 1 containing a minimum of two days in January.
Load script
SET BrokenWeeks=0;
SET ReferenceDay=2;
SET FirstWeekDay=1;
Transactions:
Load
*
Inline
[
id,date,amount
8176,12/28/2020,19.42
8177,12/29/2020,23.80
8178,12/30/2020,82.06
8179,12/31/2020,40.56
8180,01/01/2021,37.23
8181,01/02/2021,17.17
8182,01/03/2021,88.27
8183,01/04/2021,57.42
8184,01/05/2021,67.42
8185,01/06/2021,23.80
8186,01/07/2021,82.06
];
Results
Load the data and open a sheet. Create a new table.
To calculate the year that a transaction takes place in based on the week number, create the following measure:
=weekyear(date)
To calculate total sales, create the following measure:
sum(amount)
Set the measure’s Number Formatting to Money.
Results table
weekyear(date)
=sum(amount)
2020
19.42
2021
373.37
Variable
A variable in Qlik Sense is a container storing a static value or a calculation, for example a numeric or alphanumeric value.
A Qlik Sense or QlikView app: Apps are task-specific, purpose-built applications. Apps contain data loaded from data sources that is interpreted through visualizations.
The Qlik Sense Mobile app: A mobile app for iOS and Android devices. In the mobile app, you connect to and interact with your cloud data. You can work with your available apps.
The term dataset is sometimes synonymous with table. It can refer to the original source table, the table after undergoing transformations, or the fact and dimension tables in a data mart.
It can also refer to a logical table, where there are several instance tables and views:
Current data
History, which holds previous versions of the table
A preceding load is a script construct that allows you to load from the following LOAD or SELECT statement without specifying that source. Preceding loads are often faster than resident loads.
A field contains values, loaded from a data source. At a basic level, a field corresponds to a column in a table. Fields are used to create dimensions and measures in visualizations.
A measure is a calculation base on one ore more aggregations. For example, the sum of sales is a single aggregation, while the sum of sales divided by the count of customers is a measure based on two aggregations.
Sheets are components of Qlik Sense apps. They present visualizations to app users so they can explore, analyze, and discover data. Sheets can be public or private.