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.
Skip to main content Skip to complementary content

inweek - script and chart function

This function returns True if timestamp lies inside the week containing base_date.

Syntax:  

InWeek (timestamp, base_date, period_no[, first_week_day])

Return data type: Boolean

In Qlik Sense, the Boolean true value is represented by -1, and the false value is represented by 0.

Diagram of inweek() function's range

Diagram that shows how the inweek() function can be used to evaluate dates within week segments and return a Boolean result if a dat does or does not fall into a selected range.

The inweek() function uses the base_date argument to identify which seven-day period the date falls into. The start day of the week is based on the FirstWeekDay system variable. However, you can also change the first day of the week by using the first_week_day argument of the inweek() function.

After the selected week has been defined, the function will return Boolean results when comparing the prescribed date values to that week segment.

The InWeek function returns a Boolean result. Typically, this type of function will be used as a condition in an if expression. The InWeek function returns an aggregation or calculation which depends on whether a date evaluated occurred in the week with the selected date of the base_date argument.

For example, the InWeek function can be used to identify all equipment manufactured in a specific week.

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.

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 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.

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 and scripts in Qlik Cloud Analytics.

Function examples
Example Result
inweek ('01/12/2006', '01/14/2006', 0) Returns TRUE
inweek ('01/12/2006', '01/20/2006', 0 ) Returns FALSE
inweek ('01/12/2006', '01/14/2006', -1 ) Returns FALSE
inweek ('01/07/2006', '01/14/2006', -1) Returns TRUE
inweek ('01/12/2006', '01/09/2006', 0, 3) Returns FALSE because first_week_day is specified as 3 (Thursday), which makes 01/12/2006 the first day of the week following the week containing 01/09/2006.

These topics may help you work with this function:

Related topics
Topic Default Flag / Value Description
FirstWeekDay 6 / Sunday Defines the start day of each week.

Example 1 - No additional arguments

Example 2 - period_no

Example 3 - first_week_day

Example 4 - Chart object example

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