Skip to main content Skip to complementary content

monthsstart - script and chart function

This function returns a value corresponding to the timestamp of the first 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 a previous or following time period.The default output format is the DateFormat set in the script.


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

Return data type: dual

Diagram of monthsstart() function

Example diagram showing how each of the elements of the function work together to return the timestamp result. The year is broken up into a number of segments and given a date input, the function returns a timestamp value.

The monthsstart() 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 first millisecond of that segment, in date format. The function also provides the ability to return the start timestamp from preceding or following segments, as well as redefining which is the first month of the year.

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

Possible n_month arguments
Periods Number of months
month 1
bi-month 2
quarter 3
four months


half-year 6
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.

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 monthsstart() function is commonly used as part of an expression when the user would like the calculation to use the fraction of a period that has not yet occurred. This could be used, for example, to provide an input variable to let the user calculate the total interest that has been accumulated so far in the month, quarter, or half-year.

Function examples
Example Result
monthsstart(4, '10/19/2013') Returns 09/01/2013.
monthsstart(4, '10/19/2013, -1) Returns 05/01/2013.
monthsstart(4, '10/19/2013', 0, 2 ) Returns 10/01/2013, because the start of the year becomes month 2.

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.

If you are an app creator, you can set the default region for apps you create. For more information, see Setting your preferred regional settings for creating apps and scripts in Qlik Cloud Analytics.

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!