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.
This function returns a date calculated from the year YYYY, the month MM and the day DD.
Syntax:
MakeDate(YYYY [ , MM [ , DD ] ])
Return data type: dual
Arguments
Argument
Description
YYYY
The year as an integer.
MM
The month as an integer. If no month is stated, 1 (January) is assumed.
DD
The day as an integer. If no day is stated, 1 (the 1st) is assumed.
When to use it
The makedate() function would commonly be used in the script for data generation to generate a calendar. This could also be used when the date field is not directly available as date, but needs some transformations to extract year, month and day components.
These examples use the date format MM/DD/YYYY. The date format is specified in the SET DateFormat statement at the top of your data load script Change the format in the examples to suit your requirements.
Function examples
Example
Result
makedate(2012)
Returns 01/01/2012.
makedate(12)
Returns 01/01/2012.
makedate(2012,12)
Returns 12/01/2012.
makedate(2012,2,14)
Returns 02/14/2012.
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.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
transaction_year
transaction_month
transaction_day
transaction_date
Results table
transaction_year
transaction_month
transaction_day
transaction_date
2018
08
30
08/30/2018
2018
09
07
09/07/2018
2018
09
16
09/16/2018
2018
09
22
09/22/2018
2018
09
23
09/23/2018
The transaction_date field is created in the preceding load statement by using the makedate() function and passing the year, month, day fields as function arguments.
The function then combines and converts these values into a date field, returning the results in the format of the DateFormat system variable.
Example 2 – Modified DateFormat
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
The same dataset and scenario as the first example.
The creation of a field, transaction_date, in the format DD/MM/YYYY without modifying the DateFormat system variable.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
transaction_year
transaction_month
transaction_day
transaction_date
Results table
transaction_year
transaction_month
transaction_day
transaction_date
2018
08
30
30/08/2018
2018
09
07
07/09/2018
2018
09
16
16/09/2018
2018
09
22
22/09/2018
2018
09
23
23/09/2018
In this instance, the makedate() function is nested inside the date() function. The second argument of the date() function sets the format of the makedate() function results as the required DD/MM/YYYY.
Example 3 – 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 for 2018, which is loaded into a table called Transactions.
The transaction dates provided across two fields: year and month.
Create a chart object measuretransaction_date, that returns a date in the format MM/DD/YYYY.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
year
month
To determine the transaction_date, create this measure:
=makedate(transaction_year,transaction_month)
Results table
transaction_year
transaction_month
transaction_date
2018
08
08/01/2018
2018
09
09/01/2018
The transaction_date measure is created in the chart object by using the makedate() function, and passing the year and month fields as function arguments.
The function then combines these values, as well as the assumed day value of 01. These values are then converted into a date field, returning the results in the format of the DateFormat system variable.
Example 4 – Scenario
Overview
Create a calendar dataset for the calendar year of 2022.
Load script
SET DateFormat='MM/DD/YYYY';
Calendar:
load
*
where year(date)=2022;
load
date(recno()+makedate(2021,12,31)) as date
AutoGenerate 400;
Results
Results table
date
01/01/2022
01/02/2022
01/03/2022
01/04/2022
01/05/2022
01/06/2022
01/07/2022
01/08/2022
01/09/2022
01/10/2022
01/11/2022
01/12/2022
01/13/2022
01/14/2022
01/15/2022
01/16/2022
01/17/2022
01/18/2022
01/19/2022
01/20/2022
01/21/2022
01/22/2022
01/23/2022
01/24/2022
01/25/2022
+ 340 more rows
The makedate() function creates a date value for December 31, 2021. The recno() function provides the record number of the current record being loaded into the table, starting from 1. Therefore, the first record has the date January 1, 2022. Each successive recno() will then increment this date by 1. This expression is wrapped in a date() function to convert the value into a date. This process is repeated 400 times by the autogenerate function. Finally, by using a preceding load, a where condition can be used to only load dates from year 2022. This script generates a calendar containing every date in 2022.
Field
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.
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.
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 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.