Date and Time Filter Aggregation Functions
This applies to: Visual Data Discovery
To filter a custom metric using dates or times, you must already have a time attribute configured in your data source. The following date and time functions can only be used after WHERE in your custom metric.
Date field options use common time formats such as YTD, MMDDYYYY, and YoY.
The following date and time filter aggregation functions are supported.
Supported Date and Time Functions | |
---|---|
Function | Description |
DATE() | Deprecated. Use NOW() instead. |
| Deprecated. Use For example, consider this DateADD('YEAR', 1, '2021-01-01') Use this TIME_ADD('YEAR', 1, '2021-01-01') In a second example, consider this DateADD('MONTH', 1, DATE()) Use this TIME_ADD('YEAR', 1, NOW()) |
| Deprecated. Use For example, consider this DateSUB('YEAR', 1, '2021-01-01') Use this TIME_ADD('YEAR', -1, '2021-01-01' TIME_ADD supports negative |
NOW() | Obtains the current date and time for the derived field. Set the |
| This function is supported only within a TRANSFORM clause used for filtering the custom metric. The period returned is of the same length as the currently represented period, but not immediately prior to it. Instead, it counts back in The following time |
TIME() | Deprecated. Use NOW() instead. |
TIME_ADD('<time-period>',<interval>, <date-time-field>) | Adds an interval value to the In the following example, 7 is added to the hour in the field called TIME_ADD ('HOUR', +7, date_time_field) |
Date Filter Functions
Specific parameters are needed for the DateADD
and DateSub
functions. The following table describes them.
Parameter | Value |
---|---|
time_period |
Supported time periods (with corresponding interval range): |
interval | Whole number integer. Negative numbers are supported for subtraction. |
date |
|
PreviousPeriod Function
The PreviousPeriod
function is used for comparing data values between different time periods. This function can be used when you need to compare one time period to another of equivalent size for variance custom metrics. For example, comparing results from the current month to the previous month or the current week to the same week one year ago.
To use this function, the TRANSFORM
SQL-like expression must be used in the custom metric to convert the date range for a specified time attribute. For example:
SUM(Sales) TRANSFORM saledate = PreviousPeriod('month',1)
If the saledate
time period is March 2015, the custom metric returns SUM(Sales)
where the saledate
is February 2015.
PreviousPeriod
transformation is performed and it is grouped by days but transformed by units of months, quarters, or years, null values are returned when the previous period does not have matching days for the current period. For example, if the current period is the month of March and PreviousPeriod('month',1)
is used for the transformation, null values are produced for February 29-31, 2015 because those days are not valid days (although they are valid days for March 2015). Composer attempts to preserve the day-of-month correspondence between the two periods.
Specific parameters must be specified in PreviousPeriod
functions. The following table describes them.
Parameter | Value |
---|---|
offset | The time granularity for the previous period (includes |
numPeriods | The argument specifying the number of periods to go back in time. |
Comments
0 comments
Please sign in to leave a comment.