Sub topic 9
Restarting calculations with the reset parameter
This chapter assumes you can build a matrix with a row hierarchy, such as Year above Quarter. It also assumes you have written a running sum and understand the axis parameter from the previous chapters.
Why a running sum needs a restart
A running sum adds values from the first row to the current row. In a matrix with Year and Quarter on the rows, the default behavior keeps adding across the whole visual. The first quarter of 2025 then starts from the end of 2024 instead of from zero.
Often you want the total to start over for each year. The reset parameter does this. It tells the function where, in the row hierarchy, the calculation should return to its starting value.
The reset parameter
Functions that accumulate or compare across rows, such as RUNNINGSUM and MOVINGAVERAGE, accept an optional reset argument. It takes one of these values:
| Value | Behavior |
|---|---|
| NONE | Never restarts. This is the default. |
| HIGHESTPARENT | Restarts whenever the value of the highest level above the current row changes. |
| LOWESTPARENT | Restarts whenever the value of the level directly above the current row changes. |
| An integer | A positive number counts levels from the top. A negative number counts levels up from the current row. |
With a Year > Quarter hierarchy, the highest parent and the lowest parent are both Year. The two values differ once you add a third level, such as Month.
Example: a running sum per year
Put Year and Quarter on the rows of a matrix, and Sales Amount as a value. Add this visual calculation:
Running sum per year = RUNNINGSUM([Sales Amount], HIGHESTPARENT)The calculation adds quarters in order. When the Year changes, the sum drops back to the first quarter's value. The Year rows are not part of the accumulation, because the calculation runs on the lowest level of the hierarchy.
The same reset works with a moving average:
Moving average per year = MOVINGAVERAGE([Sales Amount], 3, HIGHESTPARENT)The window never reaches back into the previous year. The first quarter of each year averages only the rows that are available inside that year.
Choosing levels with an integer
An integer is useful when the hierarchy has three or more levels. Suppose the rows are Year > Quarter > Month.
1restarts at each Year. This is the same as HIGHESTPARENT.2restarts at each Quarter.-1restarts when the level one step above the current row changes. On the Month level this means each Quarter, and it matches LOWESTPARENT.
Running sum per quarter = RUNNINGSUM([Sales Amount], LOWESTPARENT)Common errors
- Nothing seems to restart. The visual has only one field on the rows. Reset needs a hierarchy above the current row, so a flat list has no parent to react to.
- The wrong level restarts. Check the order of fields on the rows. The top field is level 1, and reordering the fields changes what HIGHESTPARENT means.
- Totals look wrong. Visual calculations follow the layout. If you drag a field in or out of the visual, the restart points move with it.
Exercise
A matrix has Year, Quarter, and Month on the rows. You want a running sum of Sales Amount that starts over at the beginning of each quarter. Write the visual calculation, and give two ways to write the reset value.
Show answer
Use Running sum per quarter = RUNNINGSUM([Sales Amount], LOWESTPARENT). On the Month level, LOWESTPARENT refers to Quarter, so the sum restarts when the quarter changes. The reset value can also be the integer -1 (one level above the current row) or the integer 2 (the second level from the top, which is Quarter).