Skip to main content Skip to complementary content

monthsend - script and chart function

This function returns a value corresponding to the timestamp of the last millisecond of the month, bi-month, quarter, four-month period, or half-year containing a base date. It is also possible to find the timestamp for the end of a previous or following time period. The default output format is the DateFormat set in the script.

Syntax:  

MonthsEnd(n_months, date[, period_no [, first_month_of_year]])

Return data type: dual

Diagram of monthsend function.

Diagram showing how monthsend function can be used to identify the latest timestamp of chosen period.
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).
date The date or timestamp to evaluate.
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.

The monthsend() function divides the year into segments based on the n_months argument provided. It then evaluates what segment each date provided falls into and returns the last millisecond, in date format, of that segment. The function can return the end timestamp from preceding or following segments as well as redefine the first month of the year.

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 monthsend() function is used as part of an expression when the user would like the calculation to use the fraction of the month that has elapsed so far. The user has the opportunity, using a variable to select the period of their choosing. For example, the monthsend() can provide an input variable to let the user calculate the total interest not yet incurred during the month, quarter, or half-year.

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
monthsend(4, '07/19/2013') Returns 08/31/2013.
monthsend(4, '10/19/2013', -1) Returns 08/31/2013.
monthsend(4, '10/19/2013', 0, 2) Returns 01/31/2014.
Because the start of the year becomes month 2.

Example 1 - Basic example

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!