You need to sign in to do that
Don't have an account?

Calculating close Week based on opportunity close date
I am trying to create a formula to calculate the Week in the Year that an opportunity will close, based on the Close Date.
There was a post earlier in April on the same subject, but it remains unsolved. I have searched the help section and blogs, but cannot create the winning formula....any help is much appreciated!
Already found an issue. Here is an updated version of the formula. Also, not sure what you are saying the issue is. If you create a 'Number' formula field in the oppty and plug this in it will do the trick.
FLOOR(((CASE( MONTH( CloseDate ), 1,0, 2,31, 3,60, 4,91, 5,121, 6,152, 7,182, 8,213, 9,244, 10,274, 11,305, 12,335, 0)) - IF( MONTH( CloseDate) >= 3, (IF( MOD( YEAR( DATEVALUE(CreatedDate) ), 400) = 0, 0, IF( MOD( YEAR( DATEVALUE(CreatedDate) ), 100) = 0, 1, IF( MOD( YEAR( DATEVALUE(CreatedDate) ), 4) = 0, 0, 1)))), 0) + DAY( CloseDate )) / 7) + IF(MOD(((CASE( MONTH( CloseDate ), 1,0, 2,31, 3,60, 4,91, 5,121, 6,152, 7,182, 8,213, 9,244, 10,274, 11,305, 12,335, 0)) - IF( MONTH( CloseDate) >= 3, (IF( MOD( YEAR( DATEVALUE(CreatedDate) ), 400) = 0, 0, IF( MOD( YEAR( DATEVALUE(CreatedDate) ), 100) = 0, 1, IF( MOD( YEAR( DATEVALUE(CreatedDate) ), 4) = 0, 0, 1)))), 0) + DAY( CloseDate )), 7) = 0, 0,1)
All Answers
It is ugly but ought to do the trick. Will even account for leap years.
FLOOR(((CASE( MONTH( CloseDate ),
1,0,
2,31,
3,60,
4,91,
5,121,
6,152,
7,182,
8,213,
9,244,
10,274,
11,305,
12,335,
0)) - IF( MONTH( CloseDate) >= 3, (IF( MOD( YEAR( DATEVALUE(CreatedDate) ), 400) = 0, 0,
IF( MOD( YEAR( DATEVALUE(CreatedDate) ), 100) = 0, 1,
IF( MOD( YEAR( DATEVALUE(CreatedDate) ), 4) = 0, 0,
1)))), 0) + DAY( CloseDate )) / 7) + 1
Good grief, I was way off base with my attempts.
Many thanks...the formula has been accepted, but it does not calculate a value in the close week field based on the close date. I've updated the close date on an existing opportunity and I've created a new one, but the field is not popluating the week number.
I am looking for the same behavior of the Probability field and how it relates to the Stage field.
Already found an issue. Here is an updated version of the formula. Also, not sure what you are saying the issue is. If you create a 'Number' formula field in the oppty and plug this in it will do the trick.
FLOOR(((CASE( MONTH( CloseDate ), 1,0, 2,31, 3,60, 4,91, 5,121, 6,152, 7,182, 8,213, 9,244, 10,274, 11,305, 12,335, 0)) - IF( MONTH( CloseDate) >= 3, (IF( MOD( YEAR( DATEVALUE(CreatedDate) ), 400) = 0, 0, IF( MOD( YEAR( DATEVALUE(CreatedDate) ), 100) = 0, 1, IF( MOD( YEAR( DATEVALUE(CreatedDate) ), 4) = 0, 0, 1)))), 0) + DAY( CloseDate )) / 7) + IF(MOD(((CASE( MONTH( CloseDate ), 1,0, 2,31, 3,60, 4,91, 5,121, 6,152, 7,182, 8,213, 9,244, 10,274, 11,305, 12,335, 0)) - IF( MONTH( CloseDate) >= 3, (IF( MOD( YEAR( DATEVALUE(CreatedDate) ), 400) = 0, 0, IF( MOD( YEAR( DATEVALUE(CreatedDate) ), 100) = 0, 1, IF( MOD( YEAR( DATEVALUE(CreatedDate) ), 4) = 0, 0, 1)))), 0) + DAY( CloseDate )), 7) = 0, 0,1)
It works! Thank you...your effort is much appreciated!
Cheers.
Cleaned it up a bit.
((CloseDate - DATE(YEAR(CloseDate), 1, 1) + 1) / 7) + IF(MOD((CloseDate - DATE(YEAR(CloseDate), 1, 1) + 1), 7) = 0, 0, 1)
I just found this posting and it is almost exactly what I need. I have no idea how to read the formula itself but it works great for the most part. Is there anything that I can add to it that takes into account a fiscal 52 week year? For example, this year December 27 - 31 will end on week 53. I want to make sure that these dates are accounted for as week 1 and not week 53.
Thanks so much for the formula that has already been built. Has been a life saver for me!!!
It's not pretty but it works.
CALCULATING WORK WEEK IN YEAR (with weeks running sun. - sat. and the 53rd week of the year counting as the 1st of the following year...)
IF(
((CloseDate - DATE(YEAR(CloseDate), 1, 1) + (CASE( MOD( DATE( YEAR( CloseDate ), 01, 01 ) - DATE(1900, 1, 7), 7),
0, + 1,
6, + 7,
2, + 3,
4, + 5,
5, + 6,
1, + 2,
+ 4))) / 7) + IF(MOD((CloseDate - DATE(YEAR(CloseDate), 1, 1) + (CASE( MOD( DATE( YEAR( CloseDate ), 01, 01 ) - DATE(1900, 1, 7), 7),
0, + 1,
6, + 7,
2, + 3,
4, + 5,
5, + 6,
1, + 2,
+ 4))), 7) = 0, 0, 1)
>= 53, 1,
((CloseDate - DATE(YEAR(CloseDate), 1, 1) + (CASE( MOD( DATE( YEAR( CloseDate ), 01, 01 ) - DATE(1900, 1, 7), 7),
0, + 1,
6, + 7,
2, + 3,
4, + 5,
5, + 6,
1, + 2,
+ 4))) / 7) + IF(MOD((CloseDate - DATE(YEAR(CloseDate), 1, 1) + (CASE( MOD( DATE( YEAR( CloseDate ), 01, 01 ) - DATE(1900, 1, 7), 7),
0, + 1,
6, + 7,
2, + 3,
4, + 5,
5, + 6,
1, + 2,
+ 4))), 7) = 0, 0, 1)
)
This is very close...
It is still calculating a 53 week year though and the weird part is that it seems to now be starting it's new week on Wednesdays rather than on Sundays. Saturdays seem to be an issue too. We don't typically have weekend dates but every once in a while it comes up. Thank you again for your help with this.
Here's an excerpt that I pulled to help illustrate what's happening:
Actually, give this one a go, set it up as you did before, a number formula field with 0 deimal places.
IF( ((CloseDate - DATE(YEAR(CloseDate), 1, 1) + MOD( DATE( YEAR( CloseDate ), 01, 01 ) - DATE(1900, 1, 7), 7) + 1 ) / 7) + IF(MOD((CloseDate - DATE(YEAR(CloseDate), 1, 1) + MOD( DATE( YEAR( CloseDate ), 01, 01 ) - DATE(1900, 1, 7), 7) + 1 ), 7) = 0, 0, 1) >= 53, 1, (FLOOR((CloseDate - DATE(YEAR(CloseDate), 1, 1) + MOD( DATE( YEAR( CloseDate ), 01, 01 ) - DATE(1900, 1, 7), 7) + 1 ) / 7)) + IF(MOD((CloseDate - DATE(YEAR(CloseDate), 1, 1) + MOD( DATE( YEAR( CloseDate ), 01, 01 ) - DATE(1900, 1, 7), 7) + 1 ), 7) = 0, 0, 1) )
This worked perfectly!!! Thank you so much for all of your help!