Skip to main content Skip to complementary content

inmonths - script and chart function

This function finds if a timestamp falls within the same month, bi-month, quarter, four-month period, or half-year as a base date. It is also possible to find if the timestamp falls within a previous or following time period.

Syntax:  

InMonths(n_months, timestamp, base_date, period_no [, first_month_of_year])

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 inmonths() function

Diagram that shows the range of time in which the inmonths() function will evaluate a base date as true or false.

The inmonths() function divides the year into segments based on the n_months argument provided. It then determines whether each timestamp evaluated falls into the same segment as the base_date argument. If, however, a period_no argument is provided, the function determines whether the timestamps fall into a previous or following period from the base_date.

The following segments of the year are available in the function as n_month arguments.

n_month arguments
Period Number of months
month 1
bi-month 2
quarter 3
four months 4
half-year 6

The inmonths() function returns a Boolean result. Typically, this type of function will be used as a condition in an if expression. By using the inmonths() function, you can select the period that you want to be evaluated. For example, letting the user identify products manufactured in the month, quarter, or half-year of a certain period.

Return data type: Boolean

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

Arguments
Argument Description
n_months

The number of months that defines the period. An integer or expression that resolves to an integer that must be one of: 1 (equivalent to the inmonth() function), 2 (bi-month), 3 (equivalent to the inquarter()function), 4 (four-month period), or 6 (half year).

timestamp The date that you want to compare with base_date.
base_date Date that is used to evaluate the period.
period_no

The period can be offset by period_no, an integer, or expression resolving to an integer, where the value 0 indicates the period that contains base_date. Negative values in period_no indicate preceding periods and positive values indicate succeeding periods.

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.

Default regional settings in apps are based on the regional system settings of the computer or server where Qlik Sense is installed. If the Qlik Sense server you are accessing is set to Sweden, the Data load editor will use Swedish regional settings for dates, time, and currency. These regional format settings are not related to the language displayed in the Qlik Sense user interface. Qlik Sense will be displayed in the same language as the browser you are using.

Function examples
Example Result
inmonths(4, '01/25/2013', '04/25/2013', 0) Returns TRUE. Because the value of timestamp, 01/25/2013, lies within the four-month period 01/01/2013 to 04/30/2013, in which the value of base_date, 04/25/2013 lies.
inmonths(4, '05/25/2013', '04/25/2013', 0) Returns FALSE. Because 05/25/2013 is outside the same period as the previous example.
inmonths(4, '11/25/2012', '02/01/2013', -1 ) Returns TRUE. Because the value of period_no, -1, shifts the search period back one period of four months (the value of n-months), which makes the search period 09/01/2012 to 12/31/2012.
inmonths(4, '05/25/2006', '03/01/2006', 0, 3) Returns TRUE. Because the value of first_month_of_year is set to 3, which makes the search period 03/01/2006 to 07/30/2006 instead of 01/01/2006 to 04/30/2006.

Example 1 - No additional arguments

Example 2 - period_no

Example 3 - first_month_of_year

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!