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 four-digit year as display value with an underlying numeric value corresponding
to a timestamp of the first millisecond of the first day of the year
containing
date.
The yearname() function is different to the year() function as it lets you offset the date you want evaluated and lets you set the first month of the year.
If the first month of the year is not January, the function will return the two four-digit years across the twelve month period that contain the date. For example, if the start of the year is April and the date being evaluated is 06/30/2020, the result returned would be 2020-2021.
period_no is an integer, where the value
0 indicates the year which contains date.
Negative values in period_no indicate
preceding years and positive values indicate succeeding years.
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 display value will then be a string showing two years.
You can use the following values to set the first month of year in the first_month_of_year argument:
first_month_of_year values
Month
Value
February
2
March
3
April
4
May
5
June
6
July
7
August
8
September
9
October
10
November
11
December
12
When to use it
The yearname() function is useful for comparing aggregations by year. For example, if you want to see the total sales of products by year.
These dimensions can be created in the load script by using the function to create a field in a Master Calendar table. They can also be created in a chart as calculated dimensions
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:
date
year_name
Results table
date
year_name
01/13/2020
2020
02/26/2020
2020
03/27/2020
2020
04/16/2020
2020
05/21/2020
2020
08/14/2020
2020
10/07/2020
2020
12/05/2020
2020
01/22/2021
2021
02/03/2021
2021
03/17/2021
2021
04/23/2021
2021
05/04/2021
2021
06/30/2021
2021
07/26/2021
2021
12/27/2021
2021
06/06/2022
2022
07/18/2022
2022
11/14/2022
2022
12/12/2022
2022
The ‘year_name’ field is created in the preceding load statement by using the yearname() function and passing the date field as the function’s argument.
The yearname() function identifies which year the date value falls into and returns this as a four-digit year value.
Example 2 – period_no
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 between 2020 and 2022 is loaded into a table called ‘Transactions’.
The DateFormat system variable which is set to ‘MM/DD/YYYY’.
A preceding load that uses the yearname() and which is set as the year_name field.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
prior_year_name
Results table
date
prior_year_name
01/13/2020
2019
02/26/2020
2019
03/27/2020
2019
04/16/2020
2019
05/21/2020
2019
08/14/2020
2019
10/07/2020
2019
12/05/2020
2019
01/22/2021
2020
02/03/2021
2020
03/17/2021
2020
04/23/2021
2020
05/04/2021
2020
06/30/2021
2020
07/26/2021
2020
12/27/2021
2020
06/06/2022
2021
07/18/2022
2021
11/14/2022
2021
12/12/2022
2021
Because a period_no of -1 is used as the offset argument in the yearname() function, the function first identifies the year that the transactions take place in. The function then shifts one year prior and returns the resulting year.
Example 3 – first_month_of_year
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 DateFormat system variable which is set to ‘MM/DD/YYYY’.
A preceding load that uses the yearname() and which is set as the year_name field.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
id
date
year_name
Results table
date
year_name
01/13/2020
2019-2020
02/26/2020
2019-2020
03/27/2020
2019-2020
04/16/2020
2020-2021
05/21/2020
2020-2021
08/14/2020
2020-2021
10/07/2020
2020-2021
12/05/2020
2020-2021
01/22/2021
2020-2021
02/03/2021
2020-2021
03/17/2021
2020-2021
04/23/2021
2021-2022
05/04/2021
2021-2022
06/30/2021
2021-2022
07/26/2021
2021-2022
12/27/2021
2021-2022
06/06/2022
2022-2023
07/18/2022
2022-2023
11/14/2022
2022-2023
12/12/2022
2022-2023
Because the first_month_of_year argument of 4 is used in the yearname() function, the start of the year moves from January 1 to April 1. Therefore, each twelve month period crosses two calendar years and the yearname() function returns the two four-digit years for dates evaluated.
Transaction 8198 takes place on March 17, 2021. The yearname() function sets the beginning of the year on April 1 and the ending on March 30. Therefore, transaction 8198 occurred in the year period from April 1, 2020 and March 30, 2021. As a result, the yearname() function returns the value 2020-2021.
Example 4 – Chart object example
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 DateFormat system variable which is set to ‘MM/DD/YYYY’.
However, the field that returns the year that the transaction took place in is created as a measure in a chart object.
Load the data and open a sheet. Create a new table and add this field as a dimension:
date
To calculate the ‘year_name’ field, create this measure:
=yearname(date)
Results table
date
=yearname(date)
01/13/2020
2020
02/26/2020
2020
03/27/2020
2020
04/16/2020
2020
05/21/2020
2020
08/14/2020
2020
10/07/2020
2020
12/05/2020
2020
01/22/2021
2021
02/03/2021
2021
03/17/2021
2021
04/23/2021
2021
05/04/2021
2021
06/30/2021
2021
07/26/2021
2021
12/27/2021
2021
06/06/2022
2022
07/18/2022
2022
11/14/2022
2022
12/12/2022
2022
The ‘year_name’ measure is created in the chart object using the yearname() function and passing the date field as the function’s argument.
The yearname() function identifies which year the date value falls into and returns this as a four-digit year value.
Example 5 – Scenario
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 DateFormat system variable which is set to ‘MM/DD/YYYY’.
The end user would like a chart that presents the total sales by quarter for the transactions. Use the yearname() function as a calculated dimension to create this chart when the yearname() dimension is not available in the data model.
Load the data and open a sheet. Create a new table.
To compare aggregations by year, create this calculated dimension:
=yearname(date)
Create this measure:
=sum(amount)
Set the measure’s Number Formatting to Money.
Results table
yearname(date)
=sum(amount)
2020
$463.55
2021
$457.69
2022
$294.35
Dimension
In Analytics Services:
A dimension is an entity used to categorize data in a chart. For example, the slices in a pie chart or the bars of a bar chart represent individual values in a dimension. Dimensions are often a single field with discrete values, but can also be calculated in an expression.
A dimension is a dataset in a data mart that forms part of the star schema. Dimension datasets hold the descriptive information for all related fields that are included in the fact table’s records. A few common examples of dimension datasets are Customer and Product. Since the data in a dimension dataset is often denormalized, dimension datasets have a large number of columns.
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 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.
Charts are objects where calculations, aggregations, and groupings can be made. Graphical visualizations, such as bar charts and pie charts are common examples, but also non-graphical objects such as pivot tables are charts.
A chart consists of dimensions and measures, where the measures are calculated once per dimensional value. If the chart contains multiple dimensions, the measures are calculated once per combination of dimensional values.
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.
A dimension is an entity used to categorize data in a chart. For example, the slices in a pie chart or the bars of a bar chart represent individual values in a dimension. Dimensions are often a single field with discrete values, but can also be calculated in an expression.
A dimension is a dataset in a data mart that forms part of the star schema. Dimension datasets hold the descriptive information for all related fields that are included in the fact table’s records. A few common examples of dimension datasets are Customer and Product. Since the data in a dimension dataset is often denormalized, dimension datasets have a large number of columns.
Sheets are components of Qlik Sense apps. They present visualizations to app users so they can explore, analyze, and discover data. Sheets can be public or private.