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.
In other words, the inquarter() function divides the year into four equal quarters between January 1 and December 31. You can use the first_month_of_year argument to change what month is considered the first in your app and the quarters will change based on that argument. The base_date, the function identifies which quarter should be used as the comparator for the function. Finally, the function returns a Boolean result when comparing date values to that quarter segment.
When to use it
The inquarter() function returns a Boolean result. Typically, this type of function will be used as a condition in an if expression. This returns an aggregation or calculation that depends on whether a date occurred in the selected quarter.
For example, the inquarter() function can be used to identify all equipment manufactured in a quarter segment based on the dates when the equipment was manufactured.
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.
You can use the following values to set the first month of year in the first_month_of_year argument:
first_month_of_year values
Month
Value
February
2
March
3
April
4
May
5
June
6
July
7
August
8
September
9
October
10
November
11
December
12
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.
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 in 2022 which is loaded into a table called ‘Transactions’.
A preceding load which contains the inquarter() function that is set as the ‘in_quarter’ field and determines which transactions took place in the same quarter as May 15, 2022.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
in_quarter
Results table
date
in_quarter
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
-1
6/15/2022
-1
6/26/2022
-1
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’ field is created in the preceding load statement by using the inquarter() function. The first argument identifies which field is being evaluated. The second argument is a hard-coded date for May 15 that identifies which quarter to define as the comparator. A period_no of 0 is the final argument and ensures the inquarter() function does not compare quarters preceding or following the segmented quarter.
Any transaction that occurs between April 1 and the end of June 30 returns a Boolean result of TRUE.
Example 2 - period_no
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 in 2022 which is loaded into a table called ‘Transactions’.
A preceding load which contains the inquarter() function that is set as the ‘previous_quarter’ field, and determines which transactions took place in the quarter preceding the quarter of May 15, 2022.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
previous_qtr
Results table
date
previous_qtr
1/7/2022
-1
1/19/2022
-1
2/5/2022
-1
2/28/2022
-1
3/16/2022
-1
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
Using -1 as the period_no argument in the inquarter() function shifts the boundaries of the comparator quarter back by a full quarter. May 15 falls into the second quarter of the year and therefore the segment initially equates to the quarter of April 1 to June 30. The period_no offsets this segment by a negative three months and causes the date boundaries to become January 1 to March 30.
Therefore, any transaction that occurs between January 1 and March 30 will return a Boolean result of TRUE.
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:
A dataset containing a set of transactions in 2022 which is loaded into a table called ‘Transactions’.
A preceding load which contains the inquarter() function that is set as the ‘in_quarter’ field, and determines which transactions took place in the same quarter as May 15, 2022.
However, in this example, the organizational policy is for March to be the first month of the financial year.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
previous_qtr
Results table
date
previous_qtr
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
-1
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
Using 3 as the first_month_of_year argument in the inquarter() function sets March 1 as the start of the year and then divides the year into quarters. Therefore, the quarter segments are Mar-May, Jun-Aug, Sep-Nov, Dec-Feb. The base_date of May 15 sets the Mar-May quarter as the comparator quarter for the function.
Therefore, any transaction that occurs between March 1 and May 31 will return a Boolean result of TRUE.
Example 4 - 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 in 2022 which is loaded into a table called ‘Transactions’.
A preceding load which contains the inquarter() function that is set as the ‘in_quarter’ field, and determines which transactions took place in the same quarter as May 15, 2022.
Load the data and open a sheet. Create a new table and add this field as a dimension:
date
Create the following measure to calculate whether transactions took place in the same quarter as May 15:
=inquarter(date,'05/15/2022', 0)
Results table
date
in_quarter
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
-1
6/15/2022
-1
6/26/2022
-1
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’ measure is created in the chart by using the inquarter() function. The first argument identifies which field is being evaluated. The second argument is a hard-coded date for May 15 that identifies which quarter to define as the comparator. A period_no of 0 is the final argument and ensures the inquarter() function does not compare quarters preceding or following the segmented quarter.
Any transaction that occurs between April 1 and the end of June 30 returns a Boolean result of TRUE.
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’.
The table contains the following fields:
product ID
product type
manufacture date
cost price
It has been identified that due to equipment error, products that were manufactured in the quarter of May 15, 2022 were defective. The end user would like a chart that displays, by quarter name, the status of which products manufactured were ‘defective’ or ‘faultless’ and the cost of the products manufactured in that quarter.
Load the data and open a sheet. Create a new table and add this field as a dimension:
=quartername(manufacture_date)
Create the following measures:
=if(only(InQuarter(manufacture_date,makedate(2022,05,15),0)),'Defective','Faultless'), to identify which of the products are defective and which are faultless using the inquarter() function.
=sum(cost_price), to show the sum of the cost of each product.
The inquarter() function returns a Boolean value when evaluating the manufacturing dates of each of the products. For any product manufactured in the quarter that contains May 15, the inquarter() function returns a Boolean value of TRUE and marks the products as ‘Defective’. For any product returning a value of FALSE, and therefore not manufactured in that quarter, it marks the products as ‘Faultless’.
App
This term has several definitions:
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.
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 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.