This function returns
True if timestamp lies inside the
part of the quarter containing base_date
up until and including the last millisecond of base_date.
In Qlik Sense, the Boolean true value is represented by -1, and the false value is represented by 0.
The inquartertodate() function divides the year into four equal quarters between January 1 and December 31 (or the user-defined start of year and its corresponding end date). Using the base_date, the function will then segment a particular quarter, with the base_date identifying both which quarter and the maximum allowed date for that quarter segment. Finally, the function returns a Boolean result when comparing the prescribed date values to that segment.
Arguments
Argument
Description
timestamp
The date that you want to compare with base_date.
base_date
Date that is used to evaluate the quarter.
period_no
The quarter can be offset by period_no.
period_no is an integer, where the
value 0 indicates the quarter which contains base_date.
Negative values in period_no indicate
preceding quarters and positive values indicate succeeding quarters.
first_month_of_year
If you
want to work with (fiscal) years not starting in January, indicate
a value between 2 and 12 in first_month_of_year.
When to use it
The inquartertodate() function returns a Boolean result. Typically, this type of function will be used as a condition in an if expression. The inquartertodate() function would be used to return an aggregation or calculation dependent on whether a date evaluated occurred in the quarter up to and including the date in question.
For example, the inquartertodate() function can be used to identify all equipment manufactured in a quarter up to a specific date.
Function examples
Example
Result
inquartertodate('01/25/2013', '03/25/2013', 0)
Returns TRUE, since the value of timestamp, 01/25/2013, lies within the three-month period from 01/01/2013 to 03/25/2013, in which the value of base_date, 03/25/2013, lies.
inquartertodate('04/26/2013', '03/25/2013', 0)
Returns FALSE, since 04/26/2013 is outside the same period as the previous example.
inquartertodate('02/25/2013', '06/09/2013', -1)
Returns TRUE, since the value of period_no, -1, shifts the search period back one period of three months (one quarter of the year). This makes the search period 01/01/2013 to 03/09/2013.
inquartertodate('03/25/2006', '04/15/2006', 0, 2)
Returns TRUE, since the value of first_month_of_year is set to 2, which makes the search period 02/01/2006 to 04/15/2006 instead of 04/01/2006 to 04/15/2006.
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.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
in_quarter_to_date
Results table
date
in_quarter_to_date
1/7/2022
0
1/19/2022
0
2/5/2022
0
2/28/2022
0
3/16/2022
0
4/1/2022
-1
5/7/2022
-1
5/16/2022
0
6/15/2022
0
6/26/2022
0
7/9/2022
0
7/22/2022
0
7/23/2022
0
7/27/2022
0
8/2/2022
0
8/8/2022
0
8/19/2022
0
9/26/2022
0
10/14/2022
0
10/29/2022
0
The in_quarter_to_date field is created in the preceding load statement by using the inquartertodate() function. The first argument provided identifies which field is being evaluated. The second argument is a hard-coded date for the for May 15, which is the base_date that identifies which quarter 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 quarters preceding or following the segmented quarter.
Any transaction that occurs in between April 1 and May 15 returns a Boolean result of TRUE. Transactions dates of May 16 and later will return FALSE, as do any transactions before April 1.
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, previous_qtr_to_date, that determines which transactions took place a full quarter before the quarter segment ending on May 15, 2022.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
previous_qtr_to_date
Results table
date
previous_qtr_to_date
1/7/2022
-1
1/19/2022
-1
2/5/2022
-1
2/28/2022
0
3/16/2022
0
4/1/2022
0
5/7/2022
0
5/16/2022
0
6/15/2022
0
6/26/2022
0
7/9/2022
0
7/22/2022
0
7/23/2022
0
7/27/2022
0
8/2/2022
0
8/8/2022
0
8/19/2022
0
9/26/2022
0
10/14/2022
0
10/29/2022
0
A period_no value of -1 indicates that the inquartertodate () function compares the input quarter segment to the preceding quarter. May 15 falls into the second quarter of the year, so the segment initially equates to between April 1 and May 15. The period_no then offsets this segment by three months earlier, causing the date boundaries to become January 1 to February 15.
Therefore, any transaction that occurs between January 1 and February 15 will return a Boolean result ofTRUE.
Example 3 – first_month_of_year
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_quarter_to_date, that determines which transactions took place in the same quarter up to May 15, 2022.
In this example, we set March as the first month of the fiscal year.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
in_quarter_to_date
Results table
date
in_quarter_to_date
1/7/2022
0
1/19/2022
0
2/5/2022
0
2/28/2022
0
3/16/2022
-1
4/1/2022
-1
5/7/2022
-1
5/16/2022
0
6/15/2022
0
6/26/2022
0
7/9/2022
0
7/22/2022
0
7/23/2022
0
7/27/2022
0
8/2/2022
0
8/8/2022
0
8/19/2022
0
9/26/2022
0
10/14/2022
0
10/29/2022
0
By using 3 as the first_month_of_year argument in the inquartertodate() function, the function begins the year on March 1, and then divides the year into quarters. Therefore, the quarter segments are:
March to May
June to August
September to November
December to February
The base_date of May 15 then segments the March to May quarter by setting its end boundary as May 15.
Therefore, any transaction that occurs in between the March 1 and May 15 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 same quarter as May 15 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.
Create the following measure:
=inquartertodate(date,'05/15/2022', 0)
Results table
date
=inquartertodate(date,'05/15/2022', 0)
1/7/2022
0
1/19/2022
0
2/5/2022
0
2/28/2022
0
3/16/2022
0
4/1/2022
-1
5/7/2022
-1
5/16/2022
0
6/15/2022
0
6/26/2022
0
7/9/2022
0
7/22/2022
0
7/23/2022
0
7/27/2022
0
8/2/2022
0
8/8/2022
0
8/19/2022
0
9/26/2022
0
10/14/2022
0
10/29/2022
0
The in_quarter_to_date measure is created in a chart object by using the inquartertodate() function. The first argument is the date field being evaluated. The second argument is a hard-coded date for May 15, which is the base_date that identifies which quarter 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 quarters preceding or following the segmented quarter.
Any transaction that occurs between April 1 and May 15 returns a Boolean result of TRUE. Transactions on May 16 and later will return FALSE, as do any transactions before April 1.
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.
On May 15, 2022, a piece of equipment error was identified in the manufacturing process and resolved. Products that were manufactured in that quarter up to this date will be defective. The end user would like a chart object that displays, by quarter name, the status of whether the product is ‘defective’ or ‘faultless’ and the cost of the products manufactured in that quarter to date.
The inquartertodate() 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 quarter up to and including May 15, it marks the products as ‘Faultless’.
Aggregation
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.