If you are unable to create a new account, please email support@bspsoftware.com

 

News:

MetaManager - Administrative Tools for IBM Cognos
Pricing starting at $2,100
Download Now    Learn More

Main Menu

First day of week

Started by Nilam, 03 Mar 2014 12:20:11 AM

Previous topic - Next topic

Nilam

Hi Expert,

How to get first day of a string "Week 02 2014"?

Thanks.

navissar

#1
I don't know how your time dimension is built, but I'd try something along these lines, which is quite generic and should work in any case:

1. Break off the string to two numbers - the year and the week.
Year data item: cast(substring ([weekyear],8),integer)
Week item: cast(substring([weekyear],6,2),integer)
2. Next thing we want to do is to find out the year's first week's start date (I'm assuming your weeks begin on Monday and end on Sundays for these calcs):
first, we create a "first date of year" data item like this: _make_timestamp ([Data Item1],1,1)
Then, we find the start date for the first day of the first week (Which will usually be on the end of last year, since a year almost never begins on a Monday...)
_add_days(_add_days([first date of year],7-(_day_of_week([first date of year],1))),-6)
Let me just quickly explain that: we take 1/1/2014, for instance. It's a Wednesday, so _day_of_week will return 3 (Assuming a week beginning on Monday, Monday is 1, Tuesday is 2, Wednesday is 3). now, date+7 days-day_of_week(date) will always give the date of the LAST day of the week (On Wednesday 1/1/2014 you add 7 days and reduce 3 (the day of week for Wed.) so that's adding 4 days, which brings us to Sunday Jan 5th). We take that date and reduce 6 days to get to the FIRST day of the week (In our example, December 30 2013).
3.
Lastly, we create a data item that takes the first date of the first week and adds to it (Week (The number of week we extracted earlier)-1)*7 (So in your case, we'll add 7 days because it's week 2):
_add_days([first week of year start date],7*([Week]-1))
And that should do - this data item should return the first date of the desired week in a year.

Nilam

Thank you ..
It works

I have simplified [first week of year start date] expression as _add_days(  [first date of year] , 1 - (_day_of_week( [first date of year] ,1) )).

Thanks