This function returns
a display value showing the month (formatted according to the MonthNames script variable) and year with an underlying numeric value corresponding
to a timestamp of the first millisecond of the first day of the month.
Syntax:
MonthName(date[, period_no])
Return data type: dual
Diagram of monthname function
Arguments
Argument
Description
date
The date or timestamp to evaluate.
period_no
period_no is an integer, which, if
0 or omitted, indicates the month that contains date.
Negative values in period_no indicate
preceding months and positive values indicate succeeding months.
Function examples
Example
Result
monthname('10/19/2013')
Returns Oct
2013
monthname('10/19/2013', -1)
Returns Sep 2013
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 applications and scripts.
Default regional settings in applications 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
transaction_month
Results table
date
transaction_month
1/7/2022
Jan 2022
1/19/2022
Jan 2022
2/5/2022
Feb 2022
2/28/2022
Feb 2022
3/16/2022
Mar 2022
4/1/2022
Apr 2022
5/7/2022
May 2022
5/16/2022
May 2022
6/15/2022
Jun 2022
6/26/2022
Jun 2022
7/9/2022
Jul 2022
7/22/2022
Jul 2022
7/23/2022
Jul 2022
7/27/2022
Jul 2022
8/2/2022
Aug 2022
8/8/2022
Aug 2022
8/19/2022
Aug 2022
9/26/2022
Sep 2022
10/14/2022
Oct 2022
10/29/2022
Oct 2022
The transaction_month field is created in the preceding load statement by using the monthname() function and passing the date field as the function’s argument.
Diagram of monthname function, basic example
The monthname() function identifies that transaction 8192 took place in March 2022, and returns this value using the MonthNames system variable.
Example 2 – period_no
Overview
Open the Data load editor and add the load script below to a new section.
The load script contains:
The same inline dataset and scenario as the first example.
The creation of a field, transaction_previous_month, that returns the timestamp for the end of the month before the transaction took place.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
transaction_previous_month
Results table
date
transaction_previous_month
1/7/2022
Dec 2021
1/19/2022
Dec 2021
2/5/2022
Jan 2022
2/28/2022
Jan 2022
3/16/2022
Feb 2022
4/1/2022
Mar 2022
5/7/2022
Apr 2022
5/16/2022
Apr 2022
6/15/2022
May 2022
6/26/2022
May 2022
7/9/2022
Jun 2022
7/22/2022
Jun 2022
7/23/2022
Jun 2022
7/27/2022
Jun 2022
8/2/2022
Jul 2022
8/8/2022
Jul 2022
8/19/2022
Jul 2022
9/26/2022
Aug 2022
10/14/2022
Sep 2022
10/29/2022
Sep 2022
In this instance, because a period_no of -1 was used as the offset argument in the monthname() function, the function first identifies the month that the transactions take place in. It then shifts to one month prior and returns the month name and year.
Diagram of monthname function, period_no example
Transaction 8192 took place on March 16. The monthname() function identifies that the month before the transaction took place was February and returns the month, in the MonthNames system variable format, along with the year 2022.
The load script contains the same inline dataset and scenario as the first example. However, in this example, the unchanged dataset is loaded into the application. The calculation that returns a timestamp for the end of the month when the transactions took place is created as a measure in a chart object of the application.
Load the data and open a sheet. Create a new table and add this field as a dimension:date.
Create the following measure:
=monthname(date)
Results table
date
=monthname(date)
1/7/2022
Jan 2022
1/19/2022
Jan 2022
2/5/2022
Feb 2022
2/28/2022
Feb 2022
3/16/2022
Mar 2022
4/1/2022
Apr 2022
5/7/2022
May 2022
5/16/2022
May 2022
6/15/2022
Jun 2022
6/26/2022
Jun 2022
7/9/2022
Jul 2022
7/22/2022
Jul 2022
7/23/2022
Jul 2022
7/27/2022
Jul 2022
8/2/2022
Aug 2022
8/8/2022
Aug 2022
8/19/2022
Aug 2022
9/26/2022
Sep 2022
10/14/2022
Oct 2022
10/29/2022
Oct 2022
The month_name measure is created in the chart object by using the monthname() function and passing the date field as the function’s argument.
Diagram of monthname function, chart object example
The monthname() function identifies that transaction 8192 took place in March 2022, and returns this value using the MonthNames system variable.
Dataset
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.