Performance step up for @PRIOR

I had been considering putting pen to paper about the @XRANGE function as it has caused me pain in the past, but while I was perusing LinkedIn I can across this article by Matt Rollings where he talks about an alternative to @PRIOR and @XRANGE to improve performance.

Reporting Raja’s writeup here on @PRIOR

Knowing full well that he was right, I wanted to see what sort of impact it would actually have on my test model and was left wondering why I’d never done this before as I have done something similar with currency calculations. I’ll post about that later.

But before getting into the performance, a recap on the @XRANGE, Raja Stalvin goes into quite some to explain how @XRANGE works in his article. I have a slightly different approach to the use of @XRANGE but the net result is the same.

EPM CALC MANAGER – Unlocking Previous and Next Members: A Deep Dive into @PRIOR Functionality in Oracle EPM Calc Scripts – EPM RADIANCE

To summarise the issue Raja explains that @XRANGE includes all the level 0 members e.g. BegBalance and any other periods that may be defined, so each range of periods needs to be done individually for each year.

DO NOT DO THIS

The result will be:

Where TP1 has taken values from BegBalance not TP12.

INSTEAD

And then it’s fine, TP1 is TP12 of the previous year. Note that I restrict the periods and years in the FIX statement so that XRANGE doesn’t return an empty member set.

Performance Using xRange

However, Matt’s point was not to use this anyway, so to see how much quicker using cross dimensional references is than using @PRIOR I used the script above to calculate one account over 728k blocks.

note the message “will be executed in [CELL] mode”

Calculation time 13 seconds

For two accounts 22 seconds by adding:

For Three Accounts 29 seconds by adding this:

Using Cross Dimensional Operators

The order of precedence changes when you go to block mode, so some caution is required if the calculation has calculated dependencies. I did this in three stages to see the increment in calculation times, here is the final script I ran using a TEMPLATE

Running this across the same blocks also for one account the results are below, note the message “will be executed in [CELL] model” is absent Calculation time 7 seconds

For two accounts 8 seconds

And three accounts 10 seconds

Then I read Matt’s post again and started wondering about the use of @CURRMBR and the other functions, so I gave this a try by hard coding in the years and it saved a couple of seconds

Then I got to thinking about the overhead of all those IF tests and changed the Template to this and got it down to 5 seconds. So in this case the functions were more efficient than all those conditional tests.

Clearly the more you use the CELL mode functions the greater the benefit of a bit extra scripting.

Now I’m only left wondering why I’ve not done it this way for decades, just needed a nudge in the right direction.

Leave a Comment