You need to sign in to do that
Don't have an account?
ISO Week Calculation
In Sweden and some other parts of Europe the week numbering is often using the ISO 8601 standard that says that the first week of the year is the first week with at least 4 days in the new year. Some consequences of this is that the final dates of one year can be week 52, 53 or even week 1( in the following year). The same goes for the first dates of a year.
To be able to do weekly comparison report Year-to-Year with this weeknumbering it is necessary to create custom fields for the opportunity that calculates the Year and Week number for a given close date. Here is one solution using three custom formula fields.
Field: Global Sales Report Weekday
Description: Day 1 = Sunday, 2 = Monday....., 7=Saturday
Formula: MOD( CloseDate - DATE(1900, 1, 7), 7)+1
Field: Global Sales Report Week Year
Formula: YEAR(CloseDate + (MOD(8- Global_Sales_Report_Weekday__c ,7)-3))
Field: Global Sales Report Week
Formula:
FLOOR((CloseDate - DATE( Global_Sales_Report_Week_Year__c ,1,1) +
MOD(
(MOD( DATE(Global_Sales_Report_Week_Year__c,1,1) - DATE(1900, 1, 7), 7)+1)
+1,7)-3) / 7 + 1)
Hope this can be of use for anyone else
Peter Baeza
InfoAction AB, Sweden
This is pretty interesting. I found it to work mostly, but I am a little confused. When I have a date : 12/31/2008, the Global Report Year says 2009, and Global Report Sales Week says week 1. Is that correct?
Yes that is correct. the jan 1 2009 is a thursday so mon 29 to wed 31 2008 is in week 1 2009
/ Peter
The above formula field for week number as Apex code:
and some tests:
Please post here if you spot anything wrong with this for other years. Thanks.
Thanks eliotstock5, your method works like a charm!
Or is it possible to create a Viseualforce page that acocmplishes this?
Thanks
Sonya
thank you!
Hi,
I tried the above formula, and it was very helpful,but sometimes incorrect for certain years.
After some experimenttion, I arrived at the formula, which can be used as a formula field. This works by calculating the date of the first Monday of the year and incrementing from there ( EU week numbers start on Mondays, not Sundays, but you can adjust the below formula to suit yourself).
Formula as follows, where mDate is the date field for which you seek to return the week number...
FLOOR((( mDate -(DATE(YEAR(mDate ),1,1)-MOD(DATE(YEAR(mDate ),1,1)-2-DATE(1900,1,1),7))+
MOD(
(MOD((DATE(YEAR(mDate ),1,1)-MOD(DATE(YEAR(mDate ),1,1)-2-DATE(1900,1,1),7))-DATE(1900,1,2),7)+1)
+1,7)-3)/7+1))
NOTE 1/2: MOD( DATE( YEAR(mDate), 1, 1)-2, 7) ## returns the Monday of week 1 of the year that mDate is in
Note 2/2: The last week of december and the first week of January will be split between numbers 53 and 1. This is actually deslireabe to keep because A) it makes calculations such as finding the number of weeks between two dates accurate when one of those dates falls on week '53' B) any attempt to get around this seems to exceed the 5,000 characters for compiled code in the Salesforce formula field writer.
Works great in salesforce as well.
I have post an Idea for that problem!
Formula Function ISOWEEKNUM (https://trailblazer.salesforce.com/ideaView?id=0874V0000003lvEQAQ" target="_blank)
https://trailblazer.salesforce.com/ideaView?id=0874V0000003lvEQAQ
Thanks
Davide
https://justcannabisseed.com/grow-a-ten-pound-ten-foot-tall-cannabis-marijuana-plant/