This function calculates
the day number of the year in which a timestamp falls. The calculation is made from the first millisecond
of the first day of the year, but the first month can be offset.
Syntax:
DayNumberOfYear(timestamp[,start_month])
Return data type: integer
Arguments
Argument
Description
timestamp
The date or timestamp to evaluate.
start_month
By
specifying a start_month between
2 and 12 (1, if omitted), the beginning of the year may be moved forward
to the first day of any month. For example, if you want to work with a fiscal
year starting March 1, specify start_month
= 3.
These examples use the date format DD/MM/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
DayNumberOfYear( '12/09/2014' )
Returns 256, the day number counted from the first of the year.
DayNumberOfYear( '12/09/2014',3 )
Returns 196, the number of the day, as counted from 1 March.
Example 1 – January start of year (script)
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
A simple dataset containing a list of dates, which is loaded into a table named Calendar. The default DateFormat system variable MM/DD/YYYY is used.
A preceding load that creates an additional field named daynryear, using the DayNumberOfYear() function.
Aside from the date, no additional parameters are provided to the function.
Load script
SET DateFormat='MM/DD/YYYY';
Calendar:
Load
date,
DayNumberOfYear(date) as daynryear
;
Load
date
Inline
[
date
01/01/2022
01/10/2022
01/31/2022
02/01/2022
02/10/2022
06/30/2022
07/26/2022
10/31/2022
11/01/2022
12/31/2022
];
Results
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
daynryear
Results table
date
daynryear
01/01/2022
1
01/10/2022
10
01/31/2022
31
02/01/2022
32
02/10/2022
41
06/30/2022
182
07/26/2022
208
10/31/2022
305
11/01/2022
306
12/31/2022
366
The first day of the year is the 1st of January because no second argument was passed into the DayNumberOfYear() function.
January 1st is the 1st day of the quarter whilst February 1st is the 32nd day of the year. The 30th of June is the 182nd whilst the 31st of December is the 366th and final day of the year.
Example 2 – November start of year (script)
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
The same dataset from the first example.
The default DateFormat system variable MM/DD/YYYY is used
A start_month argument beginning on November 1. This sets the financial year to November 1.
Load script
SET DateFormat='MM/DD/YYYY';
Calendar:
Load
date,
DayNumberOfYear(date,11) as daynryear
;
Load
date
Inline
[
date
01/01/2022
01/10/2022
01/31/2022
02/01/2022
02/10/2022
06/30/2022
07/26/2022
10/31/2022
11/01/2022
12/31/2022
];
Results
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
daynryear
Results table
date
daynryear
01/01/2022
62
01/10/2022
71
01/31/2022
92
02/01/2022
93
02/10/2022
102
06/30/2022
243
07/26/2022
269
10/31/2022
366
11/01/2022
1
12/31/2022
61
The first day of the year is the 1st of November because the second argument passed into the DayNumberOfYear() function was 11.
January 1st is the 1st day of the quarter whilst February 1st is the 32nd day of the year. The 30th of June is the 182nd whilst the 31st of December is the 366th and final day of the year.
Example 3 – January start of year (chart)
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
The same dataset from the first example.
The default DateFormat system variable MM/DD/YYYY is used.
However, in this example, the unchanged dataset is loaded into the application. The value of the day of the quarter is calculated via a measure in a chart object.
Load script
SET DateFormat='MM/DD/YYYY';
Calendar:
Load
date
Inline
[
date
01/01/2022
01/10/2022
01/31/2022
02/01/2022
02/10/2022
06/30/2022
07/26/2022
10/31/2022
11/01/2022
12/31/2022
];
Results
Load the data and open a sheet. Create a new table and add this field as a dimension: date.
Create the following measure:
=daynumberofyear(date)
Results table
date
=daynumberofyear(date)
01/01/2022
1
01/10/2022
10
01/31/2022
31
02/01/2022
32
02/10/2022
41
06/30/2022
182
07/26/2022
208
10/31/2022
305
11/01/2022
306
12/31/2022
366
The first day of the year is the 1st of January because no second argument was passed into the DayNumberOfYear() function.
January 1st is the 1st day of the year whilst February 1st is the 32nd day of the year. The 30th of June is the 182nd whilst the 31st of December is the 366th and final day of the year.
Example 4 – November start of year (chart)
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
The same dataset from the first example.
The default DateFormat system variable MM/DD/YYYY is used.
The financial year runs from the 1st of November to the 31st of October.
However, in this example, the unchanged dataset is loaded into the application. The value of the day of the year is calculated via a measure in a chart object.
Load script
SET DateFormat='MM/DD/YYYY';
Calendar:
Load
date
Inline
[
date
01/01/2022
01/10/2022
01/31/2022
02/01/2022
02/10/2022
06/30/2022
07/26/2022
10/31/2022
11/01/2022
12/31/2022
];
Results
Load the data and open a sheet. Create a new table and add this field as a dimension: date.
Create the following measure:
=daynumberofyear(date)
Results table
date
=daynumberofyear(date,11)
01/01/2022
62
01/10/2022
71
01/31/2022
92
02/01/2022
93
02/10/2022
102
06/30/2022
243
07/26/2022
269
10/31/2022
366
11/01/2022
1
12/31/2022
61
The first day of the year is the 1st of November because the second argument passed into the DayNumberOfYear() function was 11.
The financial year operates between November and October. This is shown in the results table where November 1st is the 1st day of the year whilst October 31st is the 366th and last day of the year.
Load script
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 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 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.