Sub topic 9
Restarting calculations with the reset parameter
This chapter assumes you can create a visual calculation, you know the axis parameter from the previous chapter, and you have built a matrix with more than one field on its rows. Running and relative functions accept an optional reset parameter. It restarts the calculation whenever a parent value on the axis changes.
The problem: calculations that run too far
Take a matrix with Year, Quarter, and Month on the rows and Sales Amount as the value. You add a running sum:
Running sum = RUNNINGSUM([Sales Amount])At the Month level, the sum keeps growing across year and quarter boundaries. January 2025 continues from December 2024. Often that is not what you want. A year-to-date figure should start over each year, and a quarter-to-date figure should start over each quarter. The reset parameter does this.
Where reset sits in the syntax
Reset is the last optional argument of the functions that support it:
| Function | Signature (abbreviated) |
|---|---|
| RUNNINGSUM | `RUNNINGSUM(column [, axis] [, blanks] [, reset])` |
| MOVINGAVERAGE | `MOVINGAVERAGE(column [, windowSize] [, includeCurrent] [, axis] [, blanks] [, reset])` |
| PREVIOUS, NEXT | `PREVIOUS(column [, steps] [, axis] [, blanks] [, reset])` |
| FIRST, LAST | `FIRST(column [, axis] [, reset])` |
Because reset comes after the other optional arguments, you must pass something for each one before it. To skip an optional argument, leave it empty between the commas. For example, RUNNINGSUM([Sales Amount], ROWS, , HIGHESTPARENT) passes the axis, skips blanks, and sets reset.
The values reset accepts
Reset accepts one of the following:
NONE: the default. The calculation never restarts.HIGHESTPARENT: restarts when the value of the highest parent on the axis changes. On a Year > Quarter > Month axis, this is the year.LOWESTPARENT: restarts when the value of the closest parent changes. For a month row, this is the quarter.- An integer: selects a level by number.
- A positive integer is an absolute position counted from the top.
1is the highest field,2is the next one down, and so on. - A negative integer is relative to the current row's level.
-1is the direct parent,-2is the grandparent.
For a Year > Quarter > Month axis, evaluated on month rows:
| Value | Restarts when this changes | Same as |
|---|---|---|
| `NONE` | Never | Default |
| `HIGHESTPARENT` | Year | `1` |
| `LOWESTPARENT` | Quarter | `-1` |
| `2` | Quarter | Absolute position |
| `-2` | Year | Two levels up from Month |
Use the keywords when your intent is "the top" or "the nearest parent". They keep working if someone later adds a level to the hierarchy. Use positive integers when you mean a specific field, such as "always restart per Quarter". Use negative integers when the intent is relative to wherever the calculation is evaluated.
A worked example
Here is the sample data and the three running sums side by side.
| Year | Quarter | Month | Sales Amount | No reset | Reset HIGHESTPARENT | Reset LOWESTPARENT |
|---|---|---|---|---|---|---|
| 2024 | Q1 | Jan | 100 | 100 | 100 | 100 |
| 2024 | Q1 | Feb | 120 | 220 | 220 | 220 |
| 2024 | Q1 | Mar | 90 | 310 | 310 | 310 |
| 2024 | Q2 | Apr | 110 | 420 | 420 | 110 |
| 2024 | Q2 | May | 130 | 550 | 550 | 240 |
| 2024 | Q2 | Jun | 95 | 645 | 645 | 335 |
| 2025 | Q1 | Jan | 105 | 750 | 105 | 105 |
| 2025 | Q1 | Feb | 125 | 875 | 230 | 230 |
| 2025 | Q1 | Mar | 100 | 975 | 330 | 330 |
The three visual calculations are:
Running sum = RUNNINGSUM([Sales Amount])
Year to date = RUNNINGSUM([Sales Amount], ROWS, , HIGHESTPARENT)
Quarter to date = RUNNINGSUM([Sales Amount], ROWS, , LOWESTPARENT)Look at April 2024. The no-reset column carries on to 420, the year-to-date column also continues to 420, and the quarter-to-date column restarts at 110. In January 2025 both year-based and quarter-based versions restart at 105, because a new year is also a new quarter group.
The following diagram shows how the same month rows form groups under each reset setting.
Reset with relative functions
Reset also changes what PREVIOUS, NEXT, FIRST, and LAST can see. Without reset, PREVIOUS for January 2025 returns the value from December 2024. With a reset on the year, the first row of each year has no previous row within its group, so the result is blank.
Change vs previous month = [Sales Amount] - PREVIOUS([Sales Amount], 1, ROWS, , HIGHESTPARENT)Here the first month of each year has no previous row inside its year. The subtraction therefore treats the missing value as blank. If you would rather show a blank than the raw sales figure for that month, guard the expression:
Change vs previous month =
IF(
ISBLANK(PREVIOUS([Sales Amount], 1, ROWS, , HIGHESTPARENT)),
BLANK(),
[Sales Amount] - PREVIOUS([Sales Amount], 1, ROWS, , HIGHESTPARENT)
)FIRST with reset gives you the opening value of each group. This calculation shows each month's sales as a share of the first month of its year:
Index to first month = DIVIDE([Sales Amount], FIRST([Sales Amount], ROWS, HIGHESTPARENT))For 2024 this returns 1.00 for January, 1.20 for February, and 0.90 for March. For 2025 the base is the 2025 January value, 105.
Reset with moving averages
A moving average with a reset only averages rows inside the same group. At the start of each group the window has fewer rows available, so the early values are averages over what exists so far. Do not read the first values of a group as full-window averages.
Moving average in year = MOVINGAVERAGE([Sales Amount], 3, TRUE, ROWS, , HIGHESTPARENT)Compare this with the version without reset. January 2025 would otherwise average Nov and Dec 2024 into its window. With the reset, January 2025 averages only itself.
Rules and common errors
- The axis needs a hierarchy. Reset compares parent values. If the axis holds a single field, there is no parent. Nothing restarts, and
HIGHESTPARENTorLOWESTPARENThas no visible effect. Add the parent field to the same axis first. - Top-level rows have no parent. On the Year rows themselves, no reset can happen. A running sum on Year rows accumulates across all years. Each level of the matrix is calculated relative to its own parents.
- The fields must be on the axis you named. If Year, Quarter, and Month are on rows but your calculation uses
COLUMNS, the reset has nothing to compare. Keep the axis and the reset consistent. - Integers must match the structure. A positive integer larger than the number of fields on the axis, or a negative integer that reaches above the top level, is invalid and produces an error. Check the number of levels in the visual.
- Reordering changes meaning. An integer such as
2refers to a position. If you reorder the fields on the rows,2points to a different field. Keywords are safer when the hierarchy might change. - Hidden parents still count. If you hide a field in the visual, the calculation can still use it. The hidden field still defines groups on the axis. Hiding does not remove the reset boundary.
- Sorting matters. Running and relative functions follow the order shown in the visual. Reset restarts per parent group, but the order inside each group is the visual's sort order.
Choosing a value
- Decide what "start over" means in business terms: per year, per quarter, per category.
- Find which field on the axis represents that group.
- If it is the top field, use
HIGHESTPARENT. If it is the nearest parent, useLOWESTPARENT. - If it is a field in the middle, use a positive integer for its position.
- Compare the result with a
NONEversion on a few rows, as in the table above.
Exercise
A matrix has Region > Country > City on its rows. A visual calculation on city rows must restart its running sum for every country, and not for every region. Write the calculation for Sales Amount in two ways, one with a keyword and one with an integer. What happens if the calculation is moved to a visual where City is the only field on the rows?
Show answer
With a keyword: RUNNINGSUM([Sales Amount], ROWS, , LOWESTPARENT), because Country is the nearest parent of City. With an integer: RUNNINGSUM([Sales Amount], ROWS, , 2) (absolute position of Country) or RUNNINGSUM([Sales Amount], ROWS, , -1) (one level up from City). If City is the only field on the rows, there is no parent field on the axis, so nothing restarts and the sum runs across all cities. An integer like 2 would also be out of range for a one-field axis and cause an error.
Exercise
Using the sample table in this chapter, what does Quarter to date show for May 2024, and what does Year to date show for February 2025?
Show answer
Quarter to date for May 2024 is 240 (April 110 + May 130, because the sum restarted at the start of Q2). Year to date for February 2025 is 230 (January 105 + February 125, because the sum restarted at the start of 2025).