number of days in month for rule calc ?

Post Reply
BigG
Community Contributor
Posts: 211
Joined: Tue Sep 15, 2009 11:13 pm
OLAP Product: IBMPA
Version: PA 2.0 Cloud
Excel Version: 2010

number of days in month for rule calc ?

Post by BigG »

Hi,

I have a date Starting beginning of financial year. We then Have a 'Budget Number of Months' measure that users enter number of months a project will run. A rule then calculates the end date based on this month entry.

Below is the rule I use. I would like to be more accurate in the month number of days as the 365/12 sometimes targets beginning of month and other times just before. Does anyone have a suggestion on how to recognise month number days OR at least round to the closest 1st day of next month?

Code: Select all

['End Date' ]  = N: DayNo('2012-07-01') + 21916+ ['Number of Months' ]* 365/12;


thanks in advance
GG
Goatship
Posts: 33
Joined: Tue May 25, 2010 4:15 am
OLAP Product: TM1
Version: 9.5
Excel Version: 2007

Re: number of days in month for rule calc ?

Post by Goatship »

You could try adding another element calculating No of day in a month.
If ((No of Month) = Month with 31 days, then 31, continue,
If ((No of Month) = Month with 31 days, then 31, continue,
If ((No of Month) = Feb, then 28, 0 )))

Then you put this element, No of day in a month, in the rule calculating End Date.
I'm new to TM1.
Alan Kirk
Site Admin
Posts: 6647
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: number of days in month for rule calc ?

Post by Alan Kirk »

BigG wrote:Hi,

I have a date Starting beginning of financial year. We then Have a 'Budget Number of Months' measure that users enter number of months a project will run. A rule then calculates the end date based on this month entry.

Below is the rule I use. I would like to be more accurate in the month number of days as the 365/12 sometimes targets beginning of month and other times just before. Does anyone have a suggestion on how to recognise month number days OR at least round to the closest 1st day of next month?

Code: Select all

['End Date' ]  = N: DayNo('2012-07-01') + 21916+ ['Number of Months' ]* 365/12;


thanks in advance
There are probably several ways you could do that.

Edit: I've just deleted my main suggestion because I realised it would have a problem crossing calendar year barriers; I'll come back to that later. But in short it would involve extracting the date components and adding them on to the start date.

Another way would be to use a dates lookup cube.

Another, doubtless simpler and more elegant, way will probably be suggested by someone else, since the two above are just off the top of my head.
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
Alan Kirk
Site Admin
Posts: 6647
Joined: Sun May 11, 2008 2:30 am
OLAP Product: TM1
Version: PA2.0.9.18 Classic NO PAW!
Excel Version: 2013 and Office 365
Location: Sydney, Australia
Contact:

Re: number of days in month for rule calc ?

Post by Alan Kirk »

Alan Kirk wrote:Edit: I've just deleted my main suggestion because I realised it would have a problem crossing calendar year barriers; I'll come back to that later. But in short it would involve extracting the date components and adding them on to the start date.
Sorry, this is the sort of solution that I was thinking of:

Code: Select all

['End Date' ] = N: 21916+  DayNo ( DateS ( 2012+Int( (7 + ['Number of Months'] -1)/12 ), (7+['Number of Months'])-(INT((7+['Number of Months']-1)/12)*12) ,1) )  ;
In other words, you work out how many future years your month increment will take you into, and calculate the year value from that. (I've hard coded the value, but it would be possible to parse this from a start date if it's not fixed in the way your example was.)

You then work out which month of the future year it'll be by adding the number of months, and subtracting the year increment. Turn that into a date via DateS() and that into a serial date via dayno, add 21916 and you have your new Excel serial date.

It's entirely possible that there's a simpler way of doing this, and indeed the lookup cubes option would be much more straightforward (if in need of additional maintenance).
"To them, equipment failure is terrifying. To me, it’s 'Tuesday.' "
-----------
Before posting, please check the documentation, the FAQ, the Search function and FOR THE LOVE OF GLUB the Request Guidelines.
BigG
Community Contributor
Posts: 211
Joined: Tue Sep 15, 2009 11:13 pm
OLAP Product: IBMPA
Version: PA 2.0 Cloud
Excel Version: 2010

Re: number of days in month for rule calc ?

Post by BigG »

thanks for both the quick responses, I will try the last method in morning but after much fiddling I came up withthis rough and ready method... (which will probably change when I try yours). Note my date format for displaying results is MM-YYYY so I get away wit hthe code below (just make sure everything tips over 1 for next month if not already 1)

Code: Select all

#ADD MONTHS TO  1st July BUDGET YEAR
#If DAY greater than 25 (assuming never  less than 25)
['End Date' ]  = N: IF(DAY(DATE(DayNo('2012-07-01') + ['Number of Months' ]/12* 365)) >25,
#THEN  add an EXTRA 5
DayNo('2012-07-01')  + 21916+  ['Number of Months' ]/12* 365+5

#ELSE leave as is
,DayNo('2012-07-01')  + 21916+ ['Number of Months' ]/12* 365)
;
GG
BigG
Community Contributor
Posts: 211
Joined: Tue Sep 15, 2009 11:13 pm
OLAP Product: IBMPA
Version: PA 2.0 Cloud
Excel Version: 2010

Re: number of days in month for rule calc ?

Post by BigG »

sweet, cheers Alan, this is the final view

Code: Select all

['End Date'  ] = N: 21916+  
DayNo ( DateS ( DB('LU_Control', 'String', 'Start Year')
+Int( (7 + ['Number of Months'] -1)/12 ), 
(7+['Number of Months'])-(INT((7+['Number of Months']-1)/12)*12) ,1) )  ;
GG
bigA
Posts: 4
Joined: Thu Feb 16, 2012 4:29 am
OLAP Product: TM1
Version: Tm1 10_2_2
Excel Version: 2007

Re: number of days in month for rule calc ?

Post by bigA »

Hi All,

I had the same requirement to get future months date from a given point and was wondering why you needed to substract 1 as it seems like the same result with or without it.

['End Date'] =
21916 + dayno(dates(

numbr('2011')
+ int((7 + 12)/12),
(7 + 12) - (int((7 +12)/12)*12) ,1));

I could not figure out why we needed that in the logic ..Just wanted to know the reasoning behind it. Cheers
lotsaram
MVP
Posts: 3701
Joined: Fri Mar 13, 2009 11:14 am
OLAP Product: TableManager1
Version: PA 2.0.x
Excel Version: Office 365
Location: Switzerland

Re: number of days in month for rule calc ?

Post by lotsaram »

Although doing the whole calculation via rules is possible my preferred solution and advice for big A and big G would be to create a lookup cube to return the end date from a start date which was Alan's second suggestion. This approach would both simplify the rules and perform better.
4rtem
Posts: 12
Joined: Wed Nov 20, 2013 5:05 pm
OLAP Product: TM1
Version: 10.2
Excel Version: 2007

Re: number of days in month for rule calc ?

Post by 4rtem »

I use following formula in TI where period is 'YYYY-MM':
vMonthLastDate=DATE(DAYNO(TIMST(DAYNO(pPeriod | '-15')+30,'\Y-\m') | '-01')-1,1);

The logic behind is to find first date of next month and deduct it by 1.
“The way to get started is to quit talking and begin doing.” - Walt Disney
Post Reply