Functions For Referring to Past Time Periods

The following MAQL functions allow you to create metrics showing a time over time comparison (for example, month over month, or quarter over quarter) of past time periods:

Differences Between FOR Previous and FOR PreviousPeriod

The difference between the Previous( ) and PreviousPeriod( ) functions becomes clear when the date attribute in a visualization is more granular than the date attribute specified within the function’s parentheses.

FOR Previous( ) strictly follows the date attribute specified by the metric author within the parentheses of the function.

On the other hand, FOR PreviousPeriod( ) adapts to the context of the visualization. Regardless of the date attribute specified by the metric, the PreviousPeriod( ) function takes on the date attribute of the smallest granularity in the visualization.

In the following example, even though the metric in the final column has been defined as FOR PreviousPeriod(quarter), the function returns values from the previous month, as month is the most granular date attribute in this visualization.

The Previous( ) function strictly follows the date attribute specified within the function’s parentheses. PreviousPeriod ( ) takes on the most granular date attribute that is contained within the visualization.

Table comparing leads data by month and quarter, with the leads data missing for the months of April to June. The fourth and fifth columns show lead values for the previous quarter and the previous period based on the current row, respectively. Red arrows highlight how the same lead values from September appear again in December in the previous quarter column and in October in the previous period column, demonstrating the difference between FOR Previous and FOR PreviousPeriod behavior.

Even if PreviousPeriod( ) automatically takes on the granularity of the smallest date attribute in a visualization, it is still important to specify a date attribute within the PreviousPeriod( ) function as a way of specifying the date dimension of interest. This is because workspaces often have multiple date dimensions, such as Date(Lead Created), Date(MQL Qualified), or Date(Snapshot).