Calculating Last 90 day average.

Post Reply
ravi.ahuja21
Posts: 33
Joined: Tue Aug 30, 2011 8:34 am
OLAP Product: TM1
Version: 9.5
Excel Version: 10.0

Calculating Last 90 day average.

Post by ravi.ahuja21 »

Hello Folks,

I am trying to do a calculation where I have to show the user the last 90 day sales average from each day.

Below is the given output that i am expecting (For easy understanding purpose I have taken total of last 3 days for each day).

"Date", "Sales", " Last 3days Running total", "From-Todate"
1-Jan 100 100 (30dec-1jan)
2-Jan 200 300 31 dec-2jan
3-Jan 100 400 1jan-3jan
4-Jan 50 350 2jan-4jan
5-Jan 20 170 3jan-5jan
6-Jan 15 85 4jan-6jan
7-Jan 20 55 5jan-7jan
8-Jan 30 65 6jan-8jan
9-Jan 100 150 7jan-9jan
10-Jan 20 150 8jan-10jan


I am out of ideas as to how should this be calculated in TM1 it is quite easy to do in SQL query and simply populate the cube, however I do not have one dimension I have around 11 dimensions across which I need to take care of this calculation which should be done at runtime. I have already created a similar kind of a calculation in SSAS cube using MDX query, however not really getting any starting to point to write MDX query for calculating a measure value (perhaps "calculating a measure value using MDX" I dont think it is possible in TM1).



Here is the ssas code that I have used, it may not be useful but, I am not just able to absorb the fact that a thing which is possible in SSAS is not possible in TM1.

Code: Select all

Sum(
(
BottomCount(DESCENDANTS([As of Date].[Year -  Quarter -  Month -  Date].CURRENTMEMBER, [As of Date].[Year -  Quarter -  Month -  Date].[Date]),1).item(0).lag(89):
BottomCount(DESCENDANTS([As of Date].[Year -  Quarter -  Month -  Date].CURRENTMEMBER, [As of Date].[Year -  Quarter -  Month -  Date].[Date]),1).item(0)
),
[Measures].[GrossRevenue]
    ) / 90


Request the TM1 gurus to throw light on this topic.
declanr
MVP
Posts: 1831
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: Calculating Last 90 day average.

Post by declanr »

My preferred method would be to TI the average in; you just need to loop through the last 90 days (Alan has a very good topic on here about how to use dates and times), use CellGetN to add the numbers up and then when you hit 90 you could divide by 90... or also do a count while you are at it and divide by the number of populated cells... then do a CellPutN.


You could also do it by rules but that would involve creating a lot of consolidations and would probably be more work/upkeep than the TI way.

Or failing that if the data is loaded from a database elsewhere just calc the average in SQL and pop that straight in.
Declan Rodger
tomok
MVP
Posts: 2836
Joined: Tue Feb 16, 2010 2:39 pm
OLAP Product: TM1, Palo
Version: Beginning of time thru 10.2
Excel Version: 2003-2007-2010-2013
Location: Atlanta, GA
Contact:

Re: Calculating Last 90 day average.

Post by tomok »

I'll echo the sentiment that this would be better done while loading the cube and not be "at runtime" as the OP suggests. If you absolutely insist on doing it in rules then the best way is going to be to create a series of consolidations that add up the individual 90 days in question and then divide the current day with the 90 day running consolidation that corresponds to it. In theory, that would mean 365 different 90 day consolidation nodes but you probably only want business days, not weekends and holidays, so that cuts your list down but it's still a lot.

You can name your 90 day consolidation nodes so that they can be identified by the day (and use that logic in your rule, or you can create an attribute to associate the periods and use that. Assuming your measure dimension had elements for Sales and Average_Sales, and you use logic in the naming (calling the consolidation nodes 90_Day_Sales_Ending_Day1, 90_Day_Sales_Ending_Day2, etc.), the rule might look like:

Code: Select all

['Average_Sales'] = N:DB(CubeName, !Dim1, !Dim2, !Dim3,...!Dimx,!Time)\DB(CubeName, !Dim1, !Dim2, !Dim3,...!Dimx,'90_Day_Sales_Ending'|!Time);
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
Duncan P
MVP
Posts: 600
Joined: Wed Aug 17, 2011 1:19 pm
OLAP Product: TM1
Version: 9.5.2 10.1 10.2
Excel Version: 2003 2007
Location: York, UK

Re: Calculating Last 90 day average.

Post by Duncan P »

You can even put the division by 90 in as a weight of 0.01111111111111111 on each element.
tomok
MVP
Posts: 2836
Joined: Tue Feb 16, 2010 2:39 pm
OLAP Product: TM1, Palo
Version: Beginning of time thru 10.2
Excel Version: 2003-2007-2010-2013
Location: Atlanta, GA
Contact:

Re: Calculating Last 90 day average.

Post by tomok »

Duncan P wrote:You can even put the division by 90 in as a weight of 0.01111111111111111 on each element.
That's actually a way, way better way to do it, performance-wise. I use weights when calculating, monthly, quarterly, and YTD average balances for banking apps because it performs so much better. The only problem with that is you have to create different nodes for leap years.
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
ravi.ahuja21
Posts: 33
Joined: Tue Aug 30, 2011 8:34 am
OLAP Product: TM1
Version: 9.5
Excel Version: 10.0

Re: Calculating Last 90 day average.

Post by ravi.ahuja21 »

Thanks for the valuable suggestion, I will try it out and keep you guys posted.

Thanks :)
BariAbdul
Regular Participant
Posts: 424
Joined: Sat Mar 10, 2012 1:03 pm
OLAP Product: IBM TM1, Planning Analytics, P
Version: PAW 2.0.8
Excel Version: 2019

Re: Calculating Last 90 day average.

Post by BariAbdul »

ravi.ahuja21 wrote:Thanks for the valuable suggestion, I will try it out and keep you guys posted.

Thanks :)
Hi Ravi,have you been able to find the solution for this requirement,If you did could you please post it.Thanks
"You Never Fail Until You Stop Trying......"
Post Reply