Rule Efficiency

Post Reply
MarenC
Regular Participant
Posts: 432
Joined: Sat Jun 08, 2019 9:55 am
OLAP Product: Planning Analytics
Version: Planning Analytics 2.0
Excel Version: Excel 2016

Rule Efficiency

Post by MarenC »

Hi,

I came across the following rule and I felt that it was inefficient but just wanted to check here in case I missed something.

The rule is as follows:

Code: Select all

[ 'Costing %'] =N:
IF( [ 'Forecast Flag' ] = 1 &
  DB('Appointment data',Version,Year,Cost Centre,Employee,Position,'Costing %') <> 0,
	DB('Appointment data',Version,Year,Cost Centre,Employee,Position,'Costing %'),
	STET
  );
and the feeder for this is:
[ 'Forecast Flag' ]=>[ 'Costing %'];

I don't get why the DB is needed in the above rule, so I was thinking this would be better:

Code: Select all

[ 'Costing %'] =N:
IF( [ 'Forecast Flag' ] = 1,
	DB('Appointment data',Version,Year,Cost Centre,Employee,Position,'Costing %'),
	STET
  );

Then I remembered that IF statements should be avoided if possible, so I was thinking this was even better:

Code: Select all

[ 'Costing %'] =N:
[ 'Forecast Flag' ] *
DB('Appointment data',Version,Year,Cost Centre,Employee,Position,'Costing %');

Can anyone confirm that the above is correct?

Maren
declanr
MVP
Posts: 1827
Joined: Mon Dec 05, 2011 11:51 am
OLAP Product: Cognos TM1
Version: PA2.0 and most of the old ones
Excel Version: All of em
Location: Manchester, United Kingdom
Contact:

Re: Rule Efficiency

Post by declanr »

MarenC wrote: Tue Feb 25, 2025 8:22 am Hi,
I don't get why the DB is needed in the above rule, so I was thinking this would be better:
Technically it terms of performance DB performs slightly better than shorthand; you are unlikely to notice any difference from changing just 1 rule but it could add up if its every rule in a rule heavy system.
That being said it's a trade off... the shorthand does tend to make it easier to read. Which IMO is extremely important; especially in systems where there are multiple developers.

You can go for an in-between one by using shorthand but pre-fixing the element name with the dim name / hierarchy. Which again theoretically is slightly better performance than just the element name in shorthand as it means the system doesn't need to search the dims to find out where the element actually is.

In reality though - the performance difference will be incredibly negligible.

MarenC wrote: Tue Feb 25, 2025 8:22 am Then I remembered that IF statements should be avoided if possible, so I was thinking this was even better:
If statements should be avoided if they really aren't needed.

BUT in the case you have shown it looks to be making it so that the Rule is only active for forecast periods; and makes the cell editable for historic periods.
IF you also show data for history; generally keeping the IF and STET would be better as it means you can load the Actuals as real data instead of rule generated data.

Generally speaking for actuals (which don't change via user input) you are better off having everything generate by TI instead of rules... and remembering to apply security so that users can't change it!
Declan Rodger
MarenC
Regular Participant
Posts: 432
Joined: Sat Jun 08, 2019 9:55 am
OLAP Product: Planning Analytics
Version: Planning Analytics 2.0
Excel Version: Excel 2016

Re: Rule Efficiency

Post by MarenC »

Hi Declan,

Thank you for the feedback.

My apologies and I should have made this clear, the DB is to another cube, so that is required.

What I meant is, does the rule need to to have the IF for the DB, does it really need to ask whether the value is 0? Rather wouldn't it be better to remove the if for that and have this instead:

Code: Select all

[ 'Costing %'] =N:
IF( [ 'Forecast Flag' ] = 1,
	DB('Appointment data',Version,Year,Cost Centre,Employee,Position,'Costing %'),
	STET
  );
declanr
MVP
Posts: 1827
Joined: Mon Dec 05, 2011 11:51 am
OLAP Product: Cognos TM1
Version: PA2.0 and most of the old ones
Excel Version: All of em
Location: Manchester, United Kingdom
Contact:

Re: Rule Efficiency

Post by declanr »

It does look redundant.
The only reason I can think of to write the rule that way would be if you wanted to keep the cell editable so users can add a value in this cube for the non rule-derived cases.
E.g. if a % has been provided in the master cube we will use that one; otherwise users should/can add a value manually.
Declan Rodger
lotsaram
MVP
Posts: 3698
Joined: Fri Mar 13, 2009 11:14 am
OLAP Product: TableManager1
Version: PA 2.0.x
Excel Version: Office 365
Location: Switzerland

Re: Rule Efficiency

Post by lotsaram »

I think the answer depends if the STET is actually needed. As in; is the purpose of the STET to make the value 0, or to open the cell to data entry? If there are conditions where data entry is required then you need STET, otherwise I would avoid the IF and write like you did as
[ 'Forecast Flag' ] * DB('Appointment data',Version,Year,Cost Centre,Employee,Position,'Costing %')
As long as 'Forecast Flag' is a 1 or 0 Boolean then this is the way to go.

Also if you're taking efficiency then I would seriously question whether 'Costing %' needs to be fed. IMO it more than likely doesn't. It's a percentage which would indicate it is used as an intermediate driver in another calculation. Remember feeders exist in order to be able to consolidate so if there's no purpose in consolidating 'Costing %' then there's also no point in feeding it. The calculation which uses 'Costing %' will calculate just fine without 'Costing %' being fed. Whatever that downstream calculation is, that's what actually needs the feeder.
Please place all requests for help in a public thread. I will not answer PMs requesting assistance.
MarenC
Regular Participant
Posts: 432
Joined: Sat Jun 08, 2019 9:55 am
OLAP Product: Planning Analytics
Version: Planning Analytics 2.0
Excel Version: Excel 2016

Re: Rule Efficiency

Post by MarenC »

Hi,

Thank you for the responses, very insightful.

I can say for certain the STET isn't required in this cube.

The reason the Costing % might be fed is so it can be copied in TI processes, my understanding is that if the cell is not fed then it will not show up in a TI data source, unless zero cells are skipped in the TI?

Maren
User avatar
qml
MVP
Posts: 1096
Joined: Mon Feb 01, 2010 1:01 pm
OLAP Product: TM1 / Planning Analytics
Version: 2.0.9 and all previous
Excel Version: 2007 - 2016
Location: London, UK, Europe

Re: Rule Efficiency

Post by qml »

declanr wrote: Tue Feb 25, 2025 1:38 pm Technically it terms of performance DB performs slightly better than shorthand;
Are you sure? I have always worked under the understanding (confirmed with some testing a while back) that it's the opposite: the short-form/bracket notation is faster than a full DB function, and measurably so (although the difference is more pronounced with a larger number of dimensions).
Kamil Arendt
User avatar
gtonkin
MVP
Posts: 1254
Joined: Thu May 06, 2010 3:03 pm
OLAP Product: TM1
Version: Latest and greatest
Excel Version: Office 365 64-bit
Location: JHB, South Africa
Contact:

Re: Rule Efficiency

Post by gtonkin »

I was pondering Declan's statement too and went back to Cubewise's 7 tips for writing faster rules, point 6.

I have not had any cause to retest or dispute their 40% faster claim as I have seen similar results over the years.

Are there edge cases we should know about or has something changed e.g. hierarchies etc?
BR, George.

Learn something new: MDX Views
declanr
MVP
Posts: 1827
Joined: Mon Dec 05, 2011 11:51 am
OLAP Product: Cognos TM1
Version: PA2.0 and most of the old ones
Excel Version: All of em
Location: Manchester, United Kingdom
Contact:

Re: Rule Efficiency

Post by declanr »

Interesting I will cede to standing knowledge if the DB is usually significantly slower.

I was basing it on a fairly small test case I had done (all in one model) where there are a lot of hierarchies with same named elements (between hierarchies and dimensions unfortunately) - so it probably skewed the results.
Normally I would stick to shorthand (with hierarchy referenced) because I find it the most readable and that is what I find most important the majority of the time. I just have one model I work on where I was working to eke out every last drop of performance (because its massive) and the testing was a case of try everything in steps to find what worked best there.
Declan Rodger
Post Reply