inyear - script and chart function
This function returns True if timestamp lies inside the year containing base_date.
Syntax:
InYear (timestamp, base_date, period_no [, first_month_of_year])
Return data type: Boolean
In Qlik Sense, the Boolean true value is represented by -1, and the false value is represented by 0.
The inyear() function returns a Boolean result when comparing the selected date values to a year defined by the base_date.
When to use it
The inyear() function returns a Boolean result. Typically, this type of function will be used as a condition in an if expression. This returns an aggregation or calculation dependent on whether a date evaluated occurred in the year in question. For example, the inyear() function can be used to identify all sales that occurred in a defined year.
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. |
You can use the following values to set the first month of year in the first_month_of_year argument:
Month | Value |
---|---|
February | 2 |
March | 3 |
April | 4 |
May | 5 |
June | 6 |
July | 7 |
August | 8 |
September | 9 |
October | 10 |
November | 11 |
December |
12 |
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.
If you are an app creator, you can set the default region for apps you create. For more information, see Setting your preferred regional settings for creating apps and scripts in Qlik Cloud Analytics.
Example | Result |
---|---|
inyear ('01/25/2013', '01/01/2013', 0 ) | Returns TRUE |
inyear ('01/25/2012', '01/01/2013', 0) | Returns FALSE |
inyear ('01/25/2013', '01/01/2013', -1) | Returns FALSE |
inyear ('01/25/2012', '01/01/2013', -1 ) | Returns TRUE |
inyear ('01/25/2013', '01/01/2013', 0, 3) |
Returns TRUE The value of base_date and first_month_of_year specify that timestamp must fall within 01/03/2012 and 02/28/2013 |
inyear ('03/25/2013', '07/01/2013', 0, 3 ) | Returns TRUE |