Ratio calculation

Post Reply
Wim Gielis
MVP
Posts: 3241
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.1.5
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Ratio calculation

Post by Wim Gielis »

Hi all,

Just a random question - most probably there will be no right or wrong answer :-)
I am writing rules for ratios, like the following (margin calculation of turnover minus costs for example):

['MyRatio'] = ( ['A']-['B'] ) \ ['A'];

but my initial thought was to write it as:

['MyRatio'] = 1 - ['B'] \ ['A'];

Both terms are DB functions towards a cube with a great number of dimensions and detail. Form 2 will be shorter for notation.
I want to show 0 whenever A is 0, so the 2nd form will need an additional IF to test if A = 0 or not. Form 1 takes care of this as such.

What would you prefer if any? Just curious to see what you think of it.
Would there be a speed difference in the formulas as they are above, maybe because ['A'] is retrieved only once in formula 2? Or is it cached and the speed difference is minimal?

Have a great day,

Wim
Best regards,

Wim Gielis

IBM Champion 2024-2025
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
User avatar
jim wood
Site Admin
Posts: 3961
Joined: Wed May 14, 2008 1:51 pm
OLAP Product: TM1
Version: PA 2.0.7
Excel Version: Office 365
Location: 37 East 18th Street New York
Contact:

Re: Ratio calculation

Post by jim wood »

There are so many other factors that could possibly have an impact on this decision so I guess the answer would be it depends.....
Struggling through the quagmire of life to reach the other side of who knows where.
Go Build a PC
Jimbo PC Builds on YouTube
OS: Mac OS 11 PA Version: 2.0.7
User avatar
Martin Ryan
Site Admin
Posts: 2003
Joined: Sat May 10, 2008 9:08 am
OLAP Product: TM1
Version: 10.1
Excel Version: 2010
Location: Wellington, New Zealand
Contact:

Re: Ratio calculation

Post by Martin Ryan »

Give your requirement that if A is zero then the answer should be zero, I'd go with the first option. I think (but have never tested) an if statement is likely to be slower than a second retrieval. And in fact if you have to add the if statement, then you're adding in the second retrieval and the if statement. So there's more going on.

Also, to my eye, the first one is easier to comprehend as well. The second is less obvious, particularly when you obfuscate it with an if statement to boot.

Martin
Please do not send technical questions via private message or email. Post them in the forum where you'll probably get a faster reply, and everyone can benefit from the answers.
Jodi Ryan Family Lawyer
jstrygner
MVP
Posts: 195
Joined: Wed Jul 22, 2009 10:35 pm
OLAP Product: TM1
Version: 9.5.2 FP3
Excel Version: 2010

Re: Ratio calculation

Post by jstrygner »

Additionally if we consider speed, in the first one you can build difference between A and B as a consolidation with weights 1 and -1.
Wim Gielis
MVP
Posts: 3241
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.1.5
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: Ratio calculation

Post by Wim Gielis »

jstrygner wrote:Additionally if we consider speed, in the first one you can build difference between A and B as a consolidation with weights 1 and -1.
In this particular case, A and B are DB() formulas towards a second cube.
A and B would be elements in the dimension in your case (which is a good idea too).

But as we can conclude by now, there is much more going on than only the structure of the formula.

Another one of the ratio's, was:

' A
_________________

' A + B * C

I would love to implement it as: 1/ (1 + B*C/A)
... provided I add a comment in the rules or a note in the documentation on the model.
But as said, there is an important trade-off: easier formulas, readability, speed difference (if any).

Thanks for your input in this topic. Good night.
Best regards,

Wim Gielis

IBM Champion 2024-2025
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
Post Reply