A day name as defined in the environment variable DayNames.
An integer between 0-6 corresponding to the nominal day of the week (0-6).
Syntax:
weekday(date [,first_week_day=0])
Return data type: dual
The weekday() function determines which day of the week a date occurs on. It then returns a string value representing that day.
The result returns the number value corresponding to that day of the week (0-6), based on the week’s start day. For example, if the first day of the week is set to Sunday, a Wednesday will return a number value of 3. This start day is determined either by the FirstWeekDay system variable or the first_week_day function parameter.
You can use this number value as a part of an arithmetic expression. For example, multiply it by 1 to return the value itself.
When to use it
The weekday() function is useful when you want to compare aggregations by day of the week. For example, if you want to compare the average sales of products by weekday.
These dimensions can be created in the load script by using the function to create a field in a Master Calendar table; or created directly in a chart as a calculated measure.
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 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.
Information noteUnless stated otherwise, FirstWeekDay is set to 0 in these examples.
Function examples
Example
Result
weekday('10/12/1971')
Returns 'Tue' and 1.
weekday('10/12/1971' , 6)
Returns 'Tue' and 2.
In this example, Sunday (6) is the first day of the week.
SET FirstWeekDay=6;
...
weekday('10/12/1971')
Returns 'Tue' and 2.
Example 1 - Weekday string
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 2022 which is loaded into a table called ‘Transactions’.
The FirstWeekDay system variable which is set to 6 (Sunday).
The DayNames variable which is set to use the default day names.
A preceding load which contains the weekday() function, which is set as the ‘week_day’ field and returns the weekday the transactions took place.
Load script
SET DateFormat='MM/DD/YYYY';
SET DayNames='Mon;Tue;Wed;Thu;Fri;Sat;Sun';
SET FirstWeekDay=6;
Transactions:
Load
*,
WeekDay(date) as week_day
;
Load
*
Inline
[
id,date,amount
8188,01/01/2022,37.23
8189,01/02/2022,17.17
8190,01/03/2022,88.27
8191,01/04/2022,57.42
8192,01/05/2022,53.80
8193,01/06/2022,82.06
8194,01/07/2022,40.39
];
Results
Load the data and open a sheet. Create a new table and add these fields as dimensions:
id
date
week_day
Results table
id
date
week_day
8188
01/01/2022
Sat
8189
01/02/2022
Sun
8190
01/03/2022
Mon
8191
01/04/2022
Tue
8192
01/05/2022
Wed
8193
01/06/2022
Thu
8194
01/07/2022
Fri
The ‘week_day’ field is created in the preceding load statement by using the weekday() function and passing the date field as the function’s argument.
The weekday() function returns the weekday string value; that is, it returns the name of the weekday which is set by the DayNames system variable.
Transaction 8192 took place on January 5. The FirstWeekDay system variable sets the first day of the week as Sunday. The weekday() function transaction took place on a Wednesday and returns this value, in the abbreviated form of the DayNames system variable, in the week_day field.
The values in the ‘week_day’ field are right aligned in the column because there is a dual number and text result for the field (Wednesday, 3). To convert the field value into its number equivalent, the field can be wrapped inside the num() function. For example, in Transaction 8192, the Wednesday value would be converted into the number 3.
Example 2 - first_week_day
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 2022 which is loaded into a table called ‘Transactions’.
The FirstWeekDay system variable which is set to 6 (Sunday).
The DayNames variable which is set to use the default day names.
A preceding load which contains the weekday() function, which is set as the ‘week_day’ field and returns the weekday the transactions took place.
Load script
SET DateFormat='MM/DD/YYYY';
SET DayNames='Mon;Tue;Wed;Thu;Fri;Sat;Sun';
SET FirstWeekDay=6;
Transactions:
Load
*,
WeekDay(date,1) as week_day
;
Load
*
Inline
[
id,date,amount
8188,01/01/2022,37.23
8189,01/02/2022,17.17
8190,01/03/2022,88.27
8191,01/04/2022,57.42
8192,01/05/2022,53.80
8193,01/06/2022,82.06
8194,01/07/2022,40.39
];
Results
Load the data and open a sheet. Create a new table and add these fields as dimensions:
id
date
week_day
Results table
id
date
week_day
8188
01/01/2022
Sat
8189
01/02/2022
Sun
8190
01/03/2022
Mon
8191
01/04/2022
Tue
8192
01/05/2022
Wed
8193
01/06/2022
Thu
8194
01/07/2022
Fri
Because the first_week_day argument is set to 1 in the weekday() function, the first day of the week is Tuesday. Therefore, all transactions that take place on a Tuesday will have a dual number value of 0.
Transaction 8192 took place on January 5. The weekday() function identifies that this is a Wednesday, and so the expression would return the dual number value of 1.
Example 3 - Chart object example
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 2022 which is loaded into a table called ‘Transactions’.
The FirstWeekDay system variable which is set to 6 (Sunday).
The DayNames variable which is set to use the default day names.
However, in this example, the dataset is unchanged and loaded into the application. The calculation that identifies the weekday value is created as a measure in a chart in the app.
Load script
SET DateFormat='MM/DD/YYYY';
SET DayNames='Mon;Tue;Wed;Thu;Fri;Sat;Sun';
SET FirstWeekDay=6;
Transactions:
Load
*
Inline
[
id,date,amount
8188,01/01/2022,37.23
8189,01/02/2022,17.17
8190,01/03/2022,88.27
8191,01/04/2022,57.42
8192,01/05/2022,53.80
8193,01/06/2022,82.06
8194,01/07/2022,40.39
];
Results
Load the data and open a sheet. Create a new table and add these fields as dimensions:
id
date
To calculate the weekday value, create the following measure:
=weekday(date)
Results table
id
date
=weekday(date)
8188
01/01/2022
Sat
8189
01/02/2022
Sun
8190
01/03/2022
Mon
8191
01/04/2022
Tue
8192
01/05/2022
Wed
8193
01/06/2022
Thu
8194
01/07/2022
Fri
The ‘=weekday(date)’ field is created in the chart by using the weekday() function and passing the date field as the function’s argument.
The weekday() function returns the weekday string value; that is, it returns the name of the weekday which is set by the DayNames system variable.
Transaction 8192 took place on January 5. The FirstWeekDay system variable sets the first day of the week as Sunday. The weekday() function transaction took place on a Wednesday and returns this value, in the abbreviated form of the DayNames system variable, in the =weekday(date) 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 2022 which is loaded into a table called ‘Transactions’.
The FirstWeekDay system variable which is set to 6 (Sunday).
The DayNames variable which is set to use the default day names.
The end user would like a chart that presents the average sales by weekday for the transactions.
Load script
SET DateFormat='MM/DD/YYYY';
SET DayNames='Mon;Tue;Wed;Thu;Fri;Sat;Sun';
SET FirstWeekDay=6;
Transactions:
LOAD
RecNo() AS id,
MakeDate(2022, 1, Ceil(Rand() * 31)) as date,
Rand() * 1000 AS amount
Autogenerate(1000);
Results
Load the data and open a sheet. Create a new table and add these fields as dimensions:
=weekday(date)
=avg(amount)
Set the measure’s Number Formatting to Money.
Results table
weekday(date)
Avg(amount)
Sun
$536.96
Mon
$500.80
Tue
$515.63
Wed
$509.21
Thu
$482.70
Fri
$441.33
Sat
$505.22
Variable
A variable in Qlik Sense is a container storing a static value or a calculation, for example a numeric or alphanumeric value.
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.
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 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.
Charts are objects where calculations, aggregations, and groupings can be made. Graphical visualizations, such as bar charts and pie charts are common examples, but also non-graphical objects such as pivot tables are charts.
A chart consists of dimensions and measures, where the measures are calculated once per dimensional value. If the chart contains multiple dimensions, the measures are calculated once per combination of dimensional values.
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.
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 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.