Business Rule - use of And to remove IF statement

Hello,

We may have come across the forecasting requirement wherein we need to perform calculation from Current Month to Dec for Current Year and from Jan to Dec for Next Years.

Using the below pseudo code, we can achieve this requirement.

Fix ({Year}, Jan:Dec)
If @ismbr(&currentyear)
If @ismbr(&currentmonth :Dec )
Business logic
Endif
End if
Else
Business logic
Endif

If we wish to use DATACOPY, we need to eliminate IF statement because DATACOPY is not supported inside IF statement. That means we need to manage this in FIX statement and distinguish between current year and next year.

So, let's start converting if statement to fix

Fix (&currentyear,&currentmonth:Dec)
Endfix
Fix (&nextyear , Jan:Dec)
Endfix

The problem here is the code will run for all (both) the years instead of the user selected year. Now to restrict the code to run only for the user selected year we can make use of AND in our Fix statement.

Fix({Year} and &current year)
Fix (&current month : dec)
Endfix
Endfix

Fix({Year} and @list (@member(@nextsibling(& currentyear)) : @member(@shiftsibling( & current year, 3))
Fix(Jan:dec)
Endfix
Endfix

Let us analyze the script now. Imagine user is running the code for FY17 and the &current year is also set to FY17. The code will run for all the years present in the year dimension because the second fix evaluate empty set and run for entire year dimension. Now we will add SET EMPTYMEMBRSETS ON; to avoid the calculation at entire year dimension.

SET EMPTYMEMBRSETS ON;

Fix({Year} and &currentyear)
Fix (&currentmonth: dec)
Endfix
Endfix

Fix({Year} and @list(@member(@nextsibling(& currentyear)) : @member(@shiftsibling( & currentyear, 3))
Fix(Jan:dec)
Endfix
Endfix

If statements are completely removed. Now we can use data copy in the script.

Note: - There can be many cases where it's impossible to avoid if statement. This is just one of the example where if statement can be avoided.

Comments