Hi,
Well I have created a cube with Years, Days and Day measures dimensions. (I will probably end up with more dimensions and/or hierarchies within the dimensions)
The day measures include Day of the Week (Monday, Tuesday etc) and a Business Day flag (0 or 1). The Business day flag is a rule which says if the day of the week is Sunday, Saturday or blank then 0 else 1.
Against days I have created a Day of Year attribute, with 1 being 01-Jan and 366 being 31-Dec.
With this set up I have been able to create a TI process which loops through the Year dimension and the Days dimension and returns the Business Day value as it loops adding this value to a date difference variable, and restricting to only those dates that fall between the start and end date.
For information the TI code is shown below (Which while not rocket science does not fall under my idea of a fairly simple solution, so maybe I am missing something?).
I can see how this set up, i.e. creating a Cube, allows for more measures to be added and easily allows holidays to be turned on and off. So definitely an improvement on simply doing it all in a TI on an ad hoc basis.
I can’t yet see how a rule could possibly be created to find the difference between 2 dates and exclude weekends, holidays etc?
It would be nice if TM1 had more extensive functionality as with some other languages!
Update: I have added this coding to a load process and all the date differences are showing correctly. Just for context the model I am creating is for an insurance scheme that covers employee absence from work (among other things), and the days they are absent drives lots of calculations.
Code: Select all
## All on prolog for now!
# File Path for Asciioutput testing
FilePath ='XXXXXXX\';
File = GetProcessName();
# Define Start and End dates
vYearS = '2017';
vYearE = '2019';
vDayS = '15-Jun';
vDayE = '04-Jul';
# Define Loop variables
DimName = '010 Main - Days';
DimNameYr = '002 Main - Years';
vDaySDOY = AttrN(DimName, vDayS, 'Day of Year');
vDayEDOY = AttrN(DimName, vDayE, 'Day of Year');
vCube = 'Weekday';
LoopTotYr = Dimsiz(DimNameYr);
LoopTot = Dimsiz(DimName);
vDateDiff = 0;
x=1;
Y=1;
While (x< LoopTotYr);
elYr = DIMNM(DimNameYr,x);
If(DTYPE(DimNameYr, elYr) @='N');
If(Numbr(elYr) >= Numbr(vYearS) & Numbr(elYr) <= Numbr(vYearE));
While (y<=LoopTot);
el = DIMNM(DimName, y);
eldayno = Attrn(DimName, el, 'Day of Year');
If(el @<>'All Days');
If(vYearS @= vYearE);
If(eldayno >=vDaySDOY & eldayno <=vDayEDOY);
vBusDay = cellgetn(vCube, elYr, el, 'Business Day');
EndIf;
else;
If( (elYr @= vYearS & eldayno >=vDaySDOY) % (Numbr(elYr) > Numbr(vYearS) & Numbr(elYr) < Numbr(vYearE)) % (elYr @= vYearE & eldayno <=vDayEDOY));
vBusDay = cellgetn(vCube, elYr, el, 'Business Day');
EndIf;
Endif;
Endif;
vDateDiff = vDateDiff + vBusDay;
AsciiOutput( FilePath | File | '.csv', elYr, el, numbertostring(vBusDay), numbertostring(vDateDiff));
y=y+1;
vBusDay = 0;
End;
endif;
endif;
y=1;
x=x+1;
End;