In Qlik Sense, the Boolean true value is represented by -1, and the false value is represented by 0.
The inyeartodate() function will segment a particular portion of the year with the base_date, identifying the maximum allowed date for that year segment. The function then evaluates whether a date field or value falls into this segment and returns a Boolean result.
Arguments
Argument
Description
timestamp
The date that you want to compare with base_date.
base_date
Date that is used to evaluate the year.
period_no
The year can be offset by period_no.
period_no is an integer, where the
value 0 indicates the year that contains base_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.
When to use it
The inyeartodate() function returns a Boolean result. Typically, this type of function will be used as a condition in an if expression. This would return an aggregation or calculation dependent on whether a date evaluated occurred in the year up to and including the date in question.
For example, the inyeartodate() function can be used to identify all equipment manufactured in a year up to a specific date.
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
inyeartodate ('01/25/2013', '02/01/2013', 0)
Returns TRUE.
inyeartodate ('01/25/2012', '01/01/2013', 0)
Returns FALSE.
inyeartodate ('01/25/2012', '02/01/2013', -1)
Returns TRUE.
inyeartodate ('11/25/2012', '01/31/2013', 0, 4)
Returns TRUE. The value of timestamp falls inside the fiscal year beginning in the fourth month and before the value of base_date.
inyeartodate ('3/31/2013', '01/31/2013', 0, 4 )
Returns FALSE. Compared with the previous example, the value of timestamp is still inside the fiscal year, but it is after the value of base_date, so it falls outside the part of the year.
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.
Default regional settings in apps are based on the regional system settings of the computer or server where Qlik Sense is installed. If the Qlik Sense server you are accessing is set to Sweden, the Data load editor will use Swedish regional settings for dates, time, and currency. These regional format settings are not related to the language displayed in the Qlik Sense user interface. Qlik Sense will be displayed in the same language as the browser you are using.
Example 1 – No additional arguments
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, which is loaded into a table called Transactions.
The date field provided in the DateFormat system variable (MM/DD/YYYY) format.
The creation of a field, in_year_to_date, that determines which transactions took place in the year up until July 26, 2021.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
in_year_to_date
Results table
date
in_year_to_date
01/13/2020
0
02/26/2020
0
03/27/2020
0
04/16/2020
0
05/21/2020
0
06/14/2020
0
08/07/2020
0
09/05/2020
0
01/22/2021
-1
02/03/2021
-1
03/17/2021
-1
04/23/2021
-1
05/04/2021
-1
06/30/2021
-1
07/26/2021
-1
07/27/2021
0
06/06/2022
0
07/18/2022
0
11/14/2022
0
12/12/2022
0
The in_year_to_date field is created in the preceding load statement by using the inyeartodate() function. The first argument provided identifies which field is being evaluated.
The second argument is a hard-coded date for the for the July 26, 2021, which is the base_date that identifies the end boundary of the year segment. A period_no of 0 is the final argument, meaning that the function is not comparing years preceding or following the segmented year.
Any transaction that occurs in between January 1 and July 26 returns a Boolean result of TRUE. Transactions dates before 2021 and beyond July 26, 2021 return FALSE.
Example 2 – period_no
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, previous_year_to_date, that determines which transactions took place a full year before the year segment ending on July 26, 2021.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
previous_year_to_date
Results table
date
previous_year_to_date
01/13/2020
-1
02/26/2020
-1
03/27/2020
-1
04/16/2020
-1
05/21/2020
-1
06/14/2020
-1
08/07/2020
0
09/05/2020
0
01/22/2021
0
02/03/2021
0
03/17/2021
0
04/23/2021
0
05/04/2021
0
06/30/2021
0
07/26/2021
0
07/27/2021
0
06/06/2022
0
07/18/2022
0
11/14/2022
0
12/12/2022
0
A period_no value of -1 indicates that the inyeartodate () function compares the input quarter segment to the preceding year. With an input date of July 26, 2021, the segment from January 1, 2021 to July 26, 2021 was initially identified as the year-to-date. The period_no then offsets this segment by a full year earlier, causing the date boundaries to become January 1 to July 26, 2020.
Therefore, any transaction that occurs between January 1 and July 26, 2020 will return a Boolean result of TRUE.
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 and scenario as the first example.
The creation of a field, in_year_to_date, that determines which transactions took place in the same year up to July 26, 2021.
In this example, we set March as the first month of the fiscal year.
Load the data and open a sheet. Create a new table and add these fields as dimensions:
date
in_year_to_date
Results table
date
in_year_to_date
01/13/2020
0
02/26/2020
0
03/27/2020
0
04/16/2020
0
05/21/2020
0
06/14/2020
0
08/07/2020
0
09/05/2020
0
01/22/2021
0
02/03/2021
0
03/17/2021
-1
04/23/2021
-1
05/04/2021
-1
06/30/2021
-1
07/26/2021
-1
07/27/2021
0
06/06/2022
0
07/18/2022
0
11/14/2022
0
12/12/2022
0
By using 3 as the first_month_of_year argument in the inyeartodate() function, the function begins the year on March 1. The base_date of July 26, 2021 then sets the end date for that year segment.
Therefore, any transaction that occurs between March 1 and July 26, 2021 will return a Boolean result of TRUE, while transactions with dates outside these boundaries will return a value of FALSE.
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 and scenario as the first example. However, in this example, the unchanged dataset is loaded into the application. The calculation that determines which transactions took place in the same year up to July 26, 2021 is created as a measure in a chart object in 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:
=inyeartodate(date,'07/26/2021', 0)
Results table
date
=inyeartodate(date,'07/26/2021', 0)
01/13/2020
0
02/26/2020
0
03/27/2020
0
04/16/2020
0
05/21/2020
0
06/14/2020
0
08/07/2020
0
09/05/2020
0
01/22/2021
-1
02/03/2021
-1
03/17/2021
-1
04/23/2021
-1
05/04/2021
-1
06/30/2021
-1
07/26/2021
-1
07/27/2021
0
06/06/2022
0
07/18/2022
0
11/14/2022
0
12/12/2022
0
The in_year_to_date measure is created in the chart object by using the inyeartodate() function. The first argument provided identifies which field is being evaluated. The second argument is a hard-coded date for July 26, 2021, which is the base_date that identifies the end boundary of the comparator year segment. A period_no of 0 is the final argument, meaning that the function is not comparing years preceding or following the segmented year.
Any transaction that occurs between January 1 and July 26, 2021 returns a Boolean result of TRUE. Transaction dates before 2021 and after July 26, 2021 return FALSE.
Example 5 – Scenario
Overview
Open the Data load editor and add the load script below to a new tab.
The load script contains:
A dataset which is loaded into a table called Products.
Information concerning product ID, product type, manufacture date, and cost price.
The end user would like a chart object that displays, by product type, the cost of the products manufactured in 2021 up to July 26.
The inyeartodate() function returns a Boolean value when evaluating the manufacturing dates of each of the products. For any product manufactured in 2021 before July 27, the inyeartodate() function returns a Boolean value of TRUE and sums the cost_price.
Product D is the only product that was also manufactured after July 26th in 2021. The entry with product_ID 8203 was manufactured on December 27 and cost $25.12. Therefore, this cost was not included in the total for Product D in the chart object.
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!