IF Statement Evaluation in Rules

Post Reply
User avatar
20 Ton Squirrel
Posts: 71
Joined: Tue Jul 14, 2020 9:53 pm
OLAP Product: TM1
Version: Planning Analytics with Watson
Excel Version: Office 365
Location: Houston, TX

IF Statement Evaluation in Rules

Post by 20 Ton Squirrel »

Examine the example rule below:

Code: Select all

[ 'Output Value' ] = N:
    IF (  DB ( 'ExampleCubeA' , 'ExampleElementA' ) = 0
        % DB ( 'ExampleCubeB' , 'ExampleElementB' ) = 0
         , 0
         , CONTINUE 
        ) ; 
There are two conditions to be evaluated. If the first condition evaluates FALSE, does the second condition get tested or does the processor bail out?

I'm asking because I'm stuck tracking down circular references. Some rules fit this example where it was assumed the processor bails out the moment a FALSE is evaluated. If the processor evaluates the ENTIRE conditional line, I'll need to rethink these rules.
War teaches us geography, getting old teaches us biology.
User avatar
ykud
MVP
Posts: 148
Joined: Sat Jan 10, 2009 10:52 am
Contact:

Re: IF Statement Evaluation in Rules

Post by ykud »

I remember looking into this a while back and concluding that all IF conditions are evaluated, but I can't remember what example I used to conclude this (I think it was looking at rule stats to see if a measure value is being calculated where it shouldn't be). I think the order of how you write A OR B doesn't define order of calculation, e.g. that A should be evaluated before B.

Definitely caused me to rewrite some of the rules at that point and I keep writing them with this assumption since then.
MarenC
Regular Participant
Posts: 350
Joined: Sat Jun 08, 2019 9:55 am
OLAP Product: Planning Analytics
Version: Planning Analytics 2.0
Excel Version: Excel 2016

Re: IF Statement Evaluation in Rules

Post by MarenC »

Hi,

In some languages I believe the double operator, e.g. && or %%, means only evaluate where necessary, whereas a single means evaluate all results.

As for TM1, I suspect ykud is correct.

Maren
User avatar
20 Ton Squirrel
Posts: 71
Joined: Tue Jul 14, 2020 9:53 pm
OLAP Product: TM1
Version: Planning Analytics with Watson
Excel Version: Office 365
Location: Houston, TX

Re: IF Statement Evaluation in Rules

Post by 20 Ton Squirrel »

It was my programming background that led me to assume the processor aborted after a false condition. I should've written these rules more cautiously! I'll scoot the conditions within a nested IF or stagger them into separate IFs with CONTINUE. Thanks for the responses!
War teaches us geography, getting old teaches us biology.
Adam
Posts: 100
Joined: Wed Apr 03, 2019 12:10 am
OLAP Product: IBM PA
Version: 2.0.9.x
Excel Version: Microsoft 365 x64

Re: IF Statement Evaluation in Rules

Post by Adam »

Short-circuiting is the concept here, and not every language implements that. VBA also does not for those using PAXAPI.
Take care.
Adam
Post Reply