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.
In Qlik Sense, the Boolean true value is represented by -1, and the false value is represented by 0.
The inweektodate() function uses the base_date parameter to identify a maximum boundary date of a week segment, as well as its corresponding date for the start of the week, which is based on the FirstWeekDay system variable (or user-defined first_week_day parameter). Once this week segment has been defined, the function will then return Boolean results when comparing the prescribed date values to that segment.
When to use it
The inweektodate() function returns a Boolean result. Typically, this type of function will be used as a condition in an if expression. This will return an aggregation or calculation dependent on whether a date evaluated occurred during the week in question up to and including a particular date.
For example, the inweektodate() function can be used to calculate all sales made during a specified week up to a particular date.
Arguments
Argument
Description
timestamp
The date that you want to compare with base_date.
base_date
Date that is used to evaluate the week.
period_no
The week can be offset by period_no.
period_no is an integer, where the
value 0 indicates the week which contains base_date.
Negative values in period_no indicate
preceding weeks and positive values indicate succeeding weeks.
first_week_day
By default, the first day of the week is Sunday (as determined by the FirstWeekDay system variable), starting at midnight between Saturday and Sunday. The first_week_day parameter supersedes the FirstWeekDay variable. To indicate the week starting on another day, specify a flag between 0 and 6.
For a week starting on Monday and ending on Sunday, use a flag of 0 for Monday, 1 for Tuesday, 2 for Wednesday, 3 for Thursday, 4 for Friday, 5 for Saturday, and 6 for Sunday.
Function examples
Example
Interaction
inweektodate('01/12/2006', '01/12/2006', 0)
Returns TRUE.
inweektodate('01/12/2006', '01/11/2006', 0)
Returns FALSE.
inweektodate('01/12/2006', '01/18/2006', -1)
Returns FALSE. Because period_no is specified as -1, the effective data that timestamp is measured against is 01/11/2006.
inweektodate('01/11/2006', '01/12/2006', 0, 3 )
Returns FALSE, since first_week_day is specified as 3 (Thursday), which makes 01/12/2006 the first day of the week following the week containing 01/12/2006.
These topics may help you work with this function:
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.
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 month of January 2022, which is loaded into a table called Transactions.
The data field provided in the TimestampFormat='M/D/YYYY h:mm:ss[.fff]' format.
The creation of a field, in_week_to_date, which determines which transactions took place in the week up until January 14, 2022.
The creation of an additional field, named weekday, using the weekday() function. This new field is created to show which day of the week corresponds to each date.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
week_day
in_week_to_date
Results table
date
week_day
in_week_to_date
2022-01-02 12:22:06
Sun
0
2022-01-05 01:02:30
Wed
0
2022-01-06 15:36:20
Thu
0
2022-01-08 10:58:35
Sat
0
2022-01-09 08:53:32
Sun
-1
2022-01-10 21:13:01
Mon
-1
2022-01-11 00:57:13
Tue
-1
2022-01-12 09:26:02
Wed
-1
2022-01-13 15:05:09
Thu
-1
2022-01-14 18:44:57
Fri
-1
2022-01-15 06:10:46
Sat
0
2022-01-16 06:39:27
Sun
0
2022-01-17 10:44:16
Mon
0
2022-01-18 18:48:17
Tue
0
2022-01-26 04:36:03
Wed
0
2022-01-27 08:07:49
Thu
0
2022-01-28 12:24:29
Fri
0
2022-01-30 11:56:56
Sun
0
2022-01-30 14:40:19
Sun
0
2022-01-31 05:28:21
Mon
0
The in_week_to_date field is created in the preceding load statement by using the inweektodate() function. The first argument provided identifies which field is being evaluated. The second argument is a hard-coded date for January 14, which is the base_date that identifies which week to segment and defines the end boundary of that segment. A period_no of 0 is the final argument, meaning that the function is not comparing weeks preceding or following the segmented week.
The FirstWeekDay system variable determines that weeks begin on a Sunday and end on a Saturday. Therefore, January would be broken into weeks according to the diagram below, with the dates between January 9 and 14 providing the valid period for the inweekdodate() calculation:
Any transaction that occurs in between January 9 and 14 returns a Boolean result of TRUE. Transactions before and after the dates return a Boolean result of FALSE.
Example 2 – period_no
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
The same dataset and scenario as the first example.
The creation of a field, prev_week_to_date, that determines which transactions took place a full week before the week segment ending on January 14, 2022.
The creation of an additional field, named weekday, using the weekday() function. This is to show which day of the week corresponds to each date.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
week_day
prev_week_to_date
Results table
date
week_day
prev_week_to_date
2022-01-02 12:22:06
Sun
-1
2022-01-05 01:02:30
Wed
-1
2022-01-06 15:36:20
Thu
-1
2022-01-08 10:58:35
Sat
0
2022-01-09 08:53:32
Sun
0
2022-01-10 21:13:01
Mon
0
2022-01-11 00:57:13
Tue
0
2022-01-12 09:26:02
Wed
0
2022-01-13 15:05:09
Thu
0
2022-01-14 18:44:57
Fri
0
2022-01-15 06:10:46
Sat
0
2022-01-16 06:39:27
Sun
0
2022-01-17 10:44:16
Mon
0
2022-01-18 18:48:17
Tue
0
2022-01-26 04:36:03
Wed
0
2022-01-27 08:07:49
Thu
0
2022-01-28 12:24:29
Fri
0
2022-01-30 11:56:56
Sun
0
2022-01-30 14:40:19
Sun
0
2022-01-31 05:28:21
Mon
0
A period_no value of -1 indicates that the inweektodate () function compares the input quarter segment to the preceding week. The week segment initially equates to between January 9 and January 14. The period_no then offsets both the start and end boundary of this segment to one week earlier, causing the date boundaries to become January 2 to January 7.
Therefore, any transaction that occurs between January 2 and 8 (not including January 8 itself) will return a Boolean result of TRUE.
Example 3 – first_week_day
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
The same dataset and scenario as the first example.
The creation of a field, in_week_to_date, that determines which transactions took place in the week up until January 14, 2022.
The creation of an additional field, named weekday, using the weekday() function. This is to show which day of the week corresponds to each date.
In this example, we consider Monday as the first day of the week.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
week_day
in_week_to_date
Results table
date
week_day
in_week_to_date
2022-01-02 12:22:06
Sun
0
2022-01-05 01:02:30
Wed
0
2022-01-06 15:36:20
Thu
0
2022-01-08 10:58:35
Sat
0
2022-01-09 08:53:32
Sun
0
2022-01-10 21:13:01
Mon
-1
2022-01-11 00:57:13
Tue
-1
2022-01-12 09:26:02
Wed
-1
2022-01-13 15:05:09
Thu
-1
2022-01-14 18:44:57
Fri
-1
2022-01-15 06:10:46
Sat
0
2022-01-16 06:39:27
Sun
0
2022-01-17 10:44:16
Mon
0
2022-01-18 18:48:17
Tue
0
2022-01-26 04:36:03
Wed
0
2022-01-27 08:07:49
Thu
0
2022-01-28 12:24:29
Fri
0
2022-01-30 11:56:56
Sun
0
2022-01-30 14:40:19
Sun
0
2022-01-31 05:28:21
Mon
0
By using 0 as the first_week_day argument in the inweektodate() function, the function argument supersedes the FirstWeekDay system variable and sets Monday as the first day of the week.
Therefore, any transaction that occurs in between January 10 and 14 will return a Boolean result of TRUE, while transactions with dates outside these boundaries will return a value of FALSE.
The load script contains the same dataset and scenario as the first example. However, in this example, the unchanged dataset is loaded into the application. The calculation that determines which transactions took place in the week up until January 14, 2022 is created as a measure in the chart object.
Load the data and open a sheet. Create a new table and add this field as a dimension: date.
To calculate whether transactions took place in the same week up until the 14th of January, create the following measure:
=inweektodate(date,'01/14/2022',0)
To show which day of the week corresponds to each date, create an additional measure:
=weekday(date)
Results table
date
week_day
in_week_to_date
2022-01-02 12:22:06
Sun
0
2022-01-05 01:02:30
Wed
0
2022-01-06 15:36:20
Thu
0
2022-01-08 10:58:35
Sat
0
2022-01-09 08:53:32
Sun
-1
2022-01-10 21:13:01
Mon
-1
2022-01-11 00:57:13
Tue
-1
2022-01-12 09:26:02
Wed
-1
2022-01-13 15:05:09
Thu
-1
2022-01-14 18:44:57
Fri
-1
2022-01-15 06:10:46
Sat
0
2022-01-16 06:39:27
Sun
0
2022-01-17 10:44:16
Mon
0
2022-01-18 18:48:17
Tue
0
2022-01-26 04:36:03
Wed
0
2022-01-27 08:07:49
Thu
0
2022-01-28 12:24:29
Fri
0
2022-01-30 11:56:56
Sun
0
2022-01-30 14:40:19
Sun
0
2022-01-31 05:28:21
Mon
0
The in_week_to_date field is created as a measure in the chart object using the inweektodate() function. The first argument provided identifies which field is being evaluated. The second argument is a hard-coded date for January 14, which is the base_date that identifies which week to segment and defines the end boundary of that segment. A period_no of 0 is the final argument, meaning that the function is not comparing weeks preceding or following the segmented week.
The FirstWeekDay system variable determines that weeks begin on a Sunday and end on a Saturday. Therefore, January would be broken into weeks according to the diagram below, with the dates between January 9 and 14 providing the valid period for the inweekdodate() calculation:
Any transaction that occurs in between January 9 and 14 returns a Boolean result of TRUE. Transactions before and after the dates return a Boolean result of FALSE.
Example 5 – Scenario
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
A dataset which is loaded into a table called Products.
Information concerning product ID, manufacture date, and cost price.
It has been identified that due to equipment error, products that were manufactured in the week of January 12 were defective. The issue was resolved on January 13. The end user would like a chart object that displays, by week, the status of whether the products manufactured are ‘defective’ or ‘faultless’, and the cost of the products manufactured in that week.
The inweektodate() function returns a Boolean value when evaluating the manufacturing dates of each of the products. For those that return a Boolean value of TRUE, it marks the products as 'Defective'. For any product returning a value of FALSE, and therefore not made in the week up to January 12, it marks the products as ‘Faultless’.
Variable
A variable in Qlik Sense is a container storing a static value or a calculation, for example a numeric or alphanumeric value.
An aggregation is a calculation using multiple records in the source tables. Often it is a single field aggregated with a function such as sum, count, min, max, or average. For example, the sum of sales.
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 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 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.
The load script is a sequence of statements that defines what data to load and how to link the different loaded tables. It can be generated with the Data manager, or with the Data load editor, where it also can be viewed and edited.
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.
A dimension is an entity used to categorize data in a chart. For example, the slices in a pie chart or the bars of a bar chart represent individual values in a dimension. Dimensions are often a single field with discrete values, but can also be calculated in an expression.
A dimension is a dataset in a data mart that forms part of the star schema. Dimension datasets hold the descriptive information for all related fields that are included in the fact table’s records. A few common examples of dimension datasets are Customer and Product. Since the data in a dimension dataset is often denormalized, dimension datasets have a large number of columns.