Creating relative date filters
A relative date filter specifies a range of dates that are relative to the _as_of_date global parameter.
The sample Gregorian and Fiscal calendars already contain a number of predefined relative date filters. If you need custom filters, you can add them to these calendars.
Before you begin
- Know the columns in the sample calendar.
New filters are added to the sample Gregorian or Fiscal calendar data modules. To understand how these calendars are structured, look at the columns, and view dates in different columns in the same row. For example, in the Gregorian calendar data module, for the column TheDate with the value of September 30, 2018, the related values for columns dYear, PY_TheDate, and dMonth are shown in the following table:
TheDate dYear PY_TheDate dMonth 2018-09-30 2018-01-01 2017-09-30 2018-09-01
For more information, see Sample calendars.
- Conceptualize the filter lower bound and upper bound in relation to the
_as_of_date global parameter.
A relative date filter defines a range of dates between the filter lower bound (range start) and upper bound (range end) dates. The lower and upper bounds are set against a reference date that is the _as_of_date parameter value.
For example, for a year-to-date (YTD) filter, the lower bound date is the first day of the first month in the year that contains the _as_of_date date. The upper bound date is the date that is the _as_of_date parameter value. If the _as_of_date parameter is December 19, 2018 (TheDate), the lower bound date is January 1, 2018, and the upper bound date is December 19, 2018.
By default, the _as_of_date parameter has a value of today. However, it can be set to a different date. For more information, see Customizing the reference date
- Build the filter expression.
The critical element of creating a relative date filter is the filter expression. Familiarize yourself with the expression syntax and variables before you start entering the code in the expression editor. For more information, see Creating filter expressions.
folder, open the sample calendar data module where you plan to add the new
The data module contains one table with a number of existing filters. Add your new filter to this table.
- From the table context menu, click Filter.
- In the filter editor that is displayed, type the new filter name.
In the Expression pane, type or paste the filter expression.
For example, to create the Last 12 months filter, enter the following expression:
// validate: 1 = 1 #$_this.parent.idForExpression# >= #queryValue($_this.parent.split.ref + '.dMonth', $_this.parent.split.ref + '.TheDate = ' + queryValue($_this.parent.split.ref + '.PY_theDate' , $_this.parent.split.ref + '.TheDate = ' + $_as_of_date)# AND #$_this.parent.idForExpression# < #queryValue($_this.parent.split.ref + '.dMonth', $_this.parent.split.ref + '.TheDate = ' + $_as_of_date)#
Validate the expression.
Validation of date filter expressions must be done manually because the validate button in the expression editor doesn't validate macro expressions. So you can only visually confirm that the following elements are correct:
Tip: You can debug filter expressions in Reporting. To do so, open a report that contains the relative date filters, and set the validation option in the report to Information.
- The expression is preceded with the
// validate: 1 = 1comment.
- The outer block of the
queryValuemacro function is enclosed within hash marks (#).
queryValuehas matching round brackets
()for its two arguments.
- The expression is preceded with the
The new filter is added to the calendar table at the top of the list of filters. You can drag the filter to change its position in the list. The filter is created even if the expression contains errors. To modify the filter, from its context menu, click Edit filter.