function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Simonas PaulaitisSimonas Paulaitis 

How to create formula for Created Date Week Number?

Hi Guys.

I am trying to have a formula field for the Week Number of the year. So, if opportunity is created on the 3rd January 2016, it would show "Week 1 2016".
I use the report in the Matrix format.
Currently, the field I am using for week number calculation is called "Created Date"
Format of the field is: DD/MM/YYYY (this was changed in the regional settings from the american MM/DD/YYYY format)

I have browsed forums and found many formulas... which none of them work.
One of them, for example:

MOD(FLOOR((Created_Date__c - DATEVALUE( "2016-01-01 " ) ) / 7 ), 52) + 1

It gives me the following error:
Error: Invalid custom summary formula definition: Field Created_Date__c does not exist. Check spelling.

Now, I am new in SFDC formulas, so as far as I understand, there is no such field. It should be called Crated Date. But if i use just Created Date - I get error that there is no field Created. If I use formula like this:

MOD(FLOOR(("Created Date" - DATEVALUE( "2016-01-01 " ) ) / 7 ), 52) + 1

I get error: Error: Invalid custom summary formula definition: Incorrect parameter type for operator '-'. Expected Number, Date, DateTime, received Text.

I know that I am doing mistake somewhere, but where?
Thank you for the answers!

EllieAtWHLEllieAtWHL
Hi Simonas,

There are two problems with you formula as far as I can tell at the moment.
  1. The field you are trying to reference for the created date is a standard field so is referenced as CreatedDate
  2. As created date is a DateTime field, you either need to convert it to a date or convert your date to a datetime
Try using either:
MOD(FLOOR(( CreatedDate  - DATETIMEVALUE( "2016-01-01 " ) ) / 7 ), 52) + 1)
or
MOD(FLOOR(( DATEVALUE(CreatedDate)  - DATEVALUE( "2016-01-01 " ) ) / 7 ), 52) + 1)

To resolve your error messages
 
NagendraNagendra (Salesforce Developers) 
Hi Simonas,

Try this.

This formula worked for me:
MOD(FLOOR( ( DATEVALUE( CreatedDate ) - DATE(2016,01,01))/7),52)+1
You can also change the day of the week that the week starts by modifying the formula this way:
MOD(FLOOR( ( DATEVALUE( CreatedDate ) - DATE(2016,01,01)-6)/7),52)+1 
The -6 changes the week start date to Friday.  You can adjust as needed.  Hope this helps!

As created date is a standard field you have to refer it as this way CreatedDate ,which should probably resolve your issue.

Kindly mark this post as solved if the information help's so that it gets removed from the unanswered queue which results in helping others who are really in need of it.

Best Regards,
Nagendra.P
Simonas PaulaitisSimonas Paulaitis
Hi Both,

many thanks for the help. I tried all the variants proposed here with the following errors:

MOD(FLOOR( ( DATEVALUE( CreatedDate ) - DATE(2016,01,01))/7),52)+1
Error: Invalid custom summary formula definition: Field CreatedDate does not exist. Check spelling.

MOD(FLOOR(( DATEVALUE(CreatedDate)  - DATEVALUE( "2016-01-01 " ) ) / 7 ), 52) + 1)
Error: Invalid custom summary formula definition: Syntax error. Extra ')'.

MOD(FLOOR(( DATEVALUE(CreatedDate)  - DATEVALUE( "2016-01-01 " ) ) / 7 ), 52) + 1
Error: Invalid custom summary formula definition: Field CreatedDate does not exist. Check spelling.

MOD(FLOOR( ( DATEVALUE( CreatedDate ) - DATE(2016,01,01)-6)/7),52)+1 
Error: Invalid custom summary formula definition: Field CreatedDate does not exist. Check spelling.


It is interesting that if I look at the Summary Fields section, just above the Formula entering field, it lists many various fields which I could use, and Created Date is not there...
Simonas PaulaitisSimonas Paulaitis
Oh, by the way:
I tried to group the report by the Created date, using the Fiscal Week.

This gives me the week number, but it makes some sort of error.
It tells me, that Opportunity is created on the Week 51, while actually it is created on 1st of November. Which by no means can be week 51 (or week 57 some times).

Where's the problem? :(
EllieAtWHLEllieAtWHL
Simonas, from looking at your error message properly (sorry, for not doing so the first time) it looks like you are trying to build this formula on a report?

Custom formulas on reports are not very helpful, as you can only use number fields.

I would suggest you add it as a custom field on the object you are reporting on, if you can, then you can group it on the report.
Simonas PaulaitisSimonas Paulaitis

Here's additional:

Created Date: 12/01/2016 <- OK
If Grouped by Calendar Week, it is: 11/01/2016 - 17/01/2016 <- OK
If grouped by Fiscal Week: Week 3 FY 2016 <- OK

Well it looks right.

Then:

Created date: 01/11/2016 <-OK
Grouped by Calendar Week: 31/10/2016 - 06/11/2016 <- OK
Grouped by Fiscal week: Week 53 FY 2016  <- mmmm WHAT?!

Where's the problem?

Simonas PaulaitisSimonas Paulaitis
yes, I am trying to add the formula on the Report...

In this case - How to add the formula field to the opportunity?
Davide GammoneDavide Gammone
I have post an Idea for that problem!

Formula Function ISOWEEKNUM

https://trailblazer.salesforce.com/ideaView?id=0874V0000003lvEQAQ


Thanks
Davide