Iterate Formula Details
Detailed information and examples for the Iterate formula.
The Iterate formula is designed to work with embedded formulas for rolling calculations, such as cumulative sum and compound growth.
Using the Prior function, you can also retrieve the value that was calculated for the previous member. The base member in the second argument is always the starting value of the iteration.
Syntax
ITERATE([<formula>], [<base member>], [<dimensions>])
Examples
ITERATE(PRIOR () + [Balance], [Balance], [d/Date].[p/CALQUARTER])
In this example, the function calculates a rolling sum along the date dimension split in quarters based on the Balance measure. The second value is the starting value, and corresponds to the value of the base measure. For each hierarchy level, every next value is calculated by adding the previous value to the current value.
The rolling sum is aggregated at each hierarchy level. Here, year, quarters, and months.
ITERATE(PRIOR () + ([Growth]-[Expenses]), [Balance], [d/Date])
In this example, the second member Balance is the starting value, and the next value is calculated using the ([Growth]-[Expenses]) formula. The result of that formula is then added to the results of Balance.
The iteration moves along the Date dimension.
ITERATE(PRIOR () * (1 + [Growth]), [Balance], [d/Date] AND [d/Product])
ITERATE(PRIOR () * (1 + [Growth]), [Balance], [d/Date])
Using Inverse Formulas with Iterate
The Iterate formula can be used in conjunction with inverse formulas. Use inverse formulas to specify the first argument of the Iterate formula and specify how exactly to inverse the Iterate formula.
Growing Sum
ITERATE(PRIOR() + [X], [X], [d/Date])
INVERSE([X] := [SUM] - PRIOR())
INVERSE(PRIOR() := [SUM] - [X])
Balance Sheet
- Opening, which denotes the value at the start of the month or any other time period.
- Transactions, which denotes the changes within the months or other time period.
- Closing, which denotes the value at the end of the month other time period.
ITERATE(PRIOR() + [Transactions], [Transactions], [d/Date])
[Closing] - [Transactions]
Opening has the inverse formula INVERSE([Closing] := [Opening] + [Transactions]) and writes to Closing, which is a calculated account or measure. Transactions in a non-calculated account or measure.
Closing has two inverse formulas: INVERSE([Transactions] := [Closing] - PRIOR()) or INVERSE(PRIOR() := [Closing] - [Transactions]).
By doing this, the value of Transactions is adjusted accordingly when entering data. However, when entering data on Opening, the formula will try to adjust the value of Closing, which cannot adjust the value of Transactions since it’s a dependency of Opening. This would create a circular dependency. As a result, the second inverse formula is used and writes to the previous value of Closing. This will evaluate all inverse formulas again, and therefore write to the previous value of Transactions.