In Essbase calculation scripts, when an IF statement is performed, it will perform the first element of the IF statement first, check if the combination being calculated meets that criteria and calculate it if it does or pass to the next element, i.e the next ELSEIF. This will continue through all the ELSEIF statements and then the ELSE (if present) if the combination does not meet any of the criteria of the IF or ELSEIF.
It is possible to optimise an IF statement by first analysing which condition will be met by the majority of your data and then to try and place this IF statement as near to the top of your IF statement as possible ... if possible, of course.
In Sample.Basic (where Accounts and Time are dense), in order to illustrate this, I added a child of “Ratios” of “SalesYTD”. I then wrote the following Essbase Calculation script as an example:
SET UPDATECALC OFF;
"SalesYTD" = "Sales";
"SalesYTD"="Sales" + @prior("SalesYTD");
In this case, 11/12th of the data meets the criteria of the ELSE condition. Only 1/12th of the data meets the criteria of the IF. Because of the @prior function in the else condition, January would have to be calculated before all other months. I will come back to this later.
I cleared and loaded the calcdat.txt data file and ran this calculation:
Total Calc Elapsed Time for [IF.csc] : [0.203] seconds
Notice that the “SalesYTD” member is calculated in Cell mode. This means that January, because it appears before other months in the outline, will be calculated first, regardless of the IF order:
Formula for member [SalesYTD] will be executed in [CELL] mode
I then changed the calculation script, switching the order of the statements and adding a NOT operator to the first condition:
SET UPDATECALC OFF;
"SalesYTD" = "Sales" + @prior("SalesYTD");
I cleared, reloaded the calcdat.txt datafile, and re-ran the calculation.
The calculation, in this case, takes less than a quarter of the time in the first script because 11/12th of the data meet the criteria of the first statement in the IF block:
Total Calc Elapsed Time for [NOTIF.csc] : [0.047] seconds
In this example, it is imperative that the formula is calculated in outline order to get the correct results i.e. February must be calculated after January, March after February etc. You can use the @calcmode(Cell); command to force this to happen if it does not happen automatically.