This is a rewrite of this post as i completely failed to understand what i’d written. The original text is left after the break for completeness.
A week is a unit of time that has to be derived, and therefore has multiple meanings. Some business will run Monday to Friday, others will run Sunday to Saturday. To calculate the week, you need to know what date the first day of that week occurred on. This is actually quite easy to derive as you will know what day of the week the current day is. If you are running a Monday – Sunday week then if today is Tuesday, it is day 2 of the week, therefore the date the week starts will be 1 day ago. If the day is Thursday, this will be day 4 of the week, therefore the date teh week starts will be 3 days ago.
To achieve this is Cognos Report Studio we will use two funcitons.
The first function is
_day_of_week ( date_expression, integer )
The first parameter is the date you want to know the day of week of. The second paramater is the day that starts the week. 1 = Monday, 2 = Tuesday, etc. So in this case we will use the value 1. This will return the day of the week.
The second function is
_add_days ( date_expression, integer_expression )This take the first parameter, and adds to it the number of days sepcified in the second. If you prefix the second paramater with a minus (-) then it will remove that number of days.
So to work out the week number, we need to take the
Day of the week, and remove that many days from the current date. However as the first day of the week is day 1, and not day 0. So to compensate for this we need to add another day on.
The final formula would be
_add_days(cast([Transaction Date],date),-_day_of_week([Transaction Date],1)+1)