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 calculates
the day number of the quarter in which a timestamp falls. This function is used when creating a Master Calendar.
Syntax:
DayNumberOfQuarter(timestamp[,start_month])
Return data type: integer
Arguments
Argument
Description
timestamp
The date or timestamp to evaluate.
start_month
By
specifying a start_month between
2 and 12 (1, if omitted), the beginning of the year may be moved forward
to the first day of any month. For example, if you want to work with a fiscal
year starting March 1, specify start_month
= 3.
These examples use the date format DD/MM/YYYY. The date format is specified in the SET DateFormat statement at the top of your data load script. Change the format in the examples to suit your requirements.
Function examples
Example
Result
DayNumberOfQuarter('12/09/2014')
Returns 74, the day number of the current quarter.
DayNumberOfQuarter('12/09/2014',3)
Returns 12, the day number of the current quarter. In this case, the first quarter starts with March (because start_month is specified as 3). This means that the current quarter is the third quarter, which started on September 1.
Example 1 – January start of year (script)
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
A simple dataset containing a list of dates, which is loaded into a table named Calendar. The default DateFormat system variable MM/DD/YYYY is used.
A preceding load that creates an additional field named DayNrQtr, using the DayNumberOfQuarter() function.
Aside from the date, no additional parameters are provided to the function.
Load script
SET DateFormat='MM/DD/YYYY';
Calendar:
Load
date,
DayNumberOfQuarter(date) as DayNrQtr
;
Load
date
Inline
[
date
01/01/2022
01/10/2022
01/31/2022
02/01/2022
02/10/2022
02/28/2022
03/01/2022
03/31/2022
04/01/2022
];
Results
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
daynrqtr
Results table
date
daynrqtr
01/01/2022
1
01/10/2022
10
01/31/2022
31
02/01/2022
32
02/10/2022
41
02/28/2022
59
03/01/2022
61
03/31/2022
91
04/01/2022
1
The first day of the year is January 1 because no second argument was passed into the DayNumberOfQuarter() function.
January 1st is the 1st day of the quarter whilst February 1st is the 32nd day of the quarter. The 31st of March is the 91st and final day of the quarter, whilst the 1st of April is the 1st day of the 2nd Quarter.
Example 2 – February start of year (script)
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
The same dataset from the first example.
The default DateFormat system variable MM/DD/YYYY is used.
A start_month argument beginning on February 1. This sets the financial year to February 1.
Load script
SET DateFormat='MM/DD/YYYY';
Calendar:
Load
date,
DayNumberOfQuarter(date,2) as DayNrQtr
;
Load
date
Inline
[
date
01/01/2022
01/10/2022
01/31/2022
02/01/2022
02/10/2022
02/28/2022
03/01/2022
03/31/2022
04/01/2022
];
Results
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
daynrqtr
Results table
date
daynrqtr
01/01/2022
62
01/10/2022
71
01/31/2022
92
02/01/2022
1
02/10/2022
10
02/28/2022
28
03/01/2022
30
03/31/2022
60
04/01/2022
61
The first day of the year is the 1st of February because the second argument passed into the DayNumberOfQuarter() function was 2.
The first quarter of the year operates between February and April whilst the fourth quarter operates between November and January. This is shown in the results table where February 1st is the 1st day of the quarter whilst January 31st is the 92nd and last day of the quarter.
Example 3 – January start of year (chart)
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
The same dataset from the first example.
The default DateFormat system variable MM/DD/YYYY is used.
However, in this example, the unchanged dataset is loaded into the application. The value of the day of the quarter is calculated via a measure in a chart object.
Load script
SET DateFormat='MM/DD/YYYY';
Calendar:
Load
date
Inline
[
date
01/01/2022
01/10/2022
01/31/2022
02/01/2022
02/10/2022
02/28/2022
03/01/2022
03/31/2022
04/01/2022
];
Results
Load the data and open a sheet. Create a new table and add this field as a dimension: date.
Create the following measure:
=daynumberofquarter(date)
Results table
date
=daynumberofquarter(date)
01/01/2022
1
01/10/2022
10
01/31/2022
31
02/01/2022
32
02/10/2022
41
02/28/2022
59
03/01/2022
61
03/31/2022
91
04/01/2022
1
The first day of the year is the 1st of January because no second argument passed into the DayNumberOfQuarter() function.
January 1st is the 1st day of the quarter whilst February 1st is the 32nd day of the quarter. The 31st of March is the 91st and final day of the quarter, whilst the 1st of April is the 1st day of the 2nd Quarter.
Example 4 – February start of year (chart)
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
The same dataset from the first example.
The default DateFormat system variable MM/DD/YYYY is used.
The financial year runs from the 1st of February to the 31st of January.
However, in this example, the unchanged dataset is loaded into the application. The value of the day of the quarter is calculated via a measure in a chart object.
Load script
SET DateFormat='MM/DD/YYYY';
Calendar:
Load
date
Inline
[
date
01/01/2022
01/10/2022
01/31/2022
02/01/2022
02/10/2022
02/28/2022
03/01/2022
03/31/2022
04/01/2022
];
Chart object
Load the data and open a sheet. Create a new table and add this field as a dimension: date.
Create the following measure:
=daynumberofquarter(date,2)
Results
Results table
date
=daynumberofquarter(date,2)
01/01/2022
62
01/10/2022
71
01/31/2022
92
02/01/2022
1
02/10/2022
10
02/28/2022
28
03/01/2022
30
03/31/2022
60
04/01/2022
61
The first day of the year is the 1st of January because the second argument passed into the DayNumberOfQuarter() function was 2.
The first quarter of the year operates between February and April whilst the fourth quarter operates between November and January. This is evidenced in the results table where February 1st is the 1st day of the quarter whilst January 31st is the 92nd and last day of the quarter.
Load script
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.
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.