PREV(property[, num records back])
NEXT(property[, num records forward])
It is often helpful to put data in context by displaying what that data was in a previous timeframe.
To do this, you use the PREV and NEXT commands:
- PREV - Go some number of records backward
- NEXT - Go some number of records forward (note that if your report is trending backward in time, you will want to use the NEXT command to compare to previous time periods)
PREV and NEXT are most often combined with aggregates, but may be used at the datapoint level as well. To see example reports using the PREV and NEXT functions, click here.
These functions take the following arguments:
- A property (or aggregate)
- How many records to go forward or backward (defaults to 1)
{|RESULT|}<table class='data'>
<thead>
<tr>
<th>ID</th>
<th>Date</th>
<th>Score</th>
<th>Score of Previous Shop</th>
</tr>
</thead>
<tbody>
{|LOOP|RESULT.DATAPOINTS(SORT=TRENDING_TIMESTAMP)}
<tr>
<th>{DATAPOINTS.DATAPOINT_ID}</th>
<td>{DATAPOINTS.TRENDING_TIMESTAMP}</td>
#the current datapoint's score
<td>{DATAPOINTS.SCORE}</td>
#the previous datapoint's score
<td>{PREV(DATAPOINTS.SCORE)}</td>
</tr>
{/|LOOP|}
</tbody>
</table>
{/|RESULT|}
{|CROSSTAB|}
{|LOOP|CROSSTAB.LOCATION(SORT=ORDER_NUM)}
{|SHOWIF|LOOP.ISFIRST}
<table class='data'>
<thead>
<tr>
<th>Name</th>
#note that we're sorting our month-years backward
{|LOOP|LOCATION.MONTH_YEAR(SORT=ORDER_NUM|DESC)}
<th>{MONTH_YEAR.NAME} Score</th>
<th>{MONTH_YEAR.NAME} Score 6 Months Ago</th>
{/|LOOP|}
</tr>
</thead>
<tbody>
{/|SHOWIF|}
<tr>
<th>{LOCATION.NAME}</th>
{|LOOP|LOCATION.MONTH_YEAR}
#the current location's average score for this month/year
<td>{AVG(MONTH_YEAR.SCORE)}</td>
#the current location's average score 6 months ago
#note the use of NEXT because we're trending backward
<td>{NEXT(AVG(MONTH_YEAR.SCORE), 6)}</td>
{/|LOOP|}
</tr>
{|VANISHIF|LOOP.HASNEXT}
</tbody>
</table>
{/|VANISHIF|}
{/|LOOP|}
{/|CROSSTAB|}