You need to sign in to do that
Don't have an account?
Dorel Nasso 9
Need a formula to calculate a date field counting backwards from another date field that excludes weekends.
IF(MOD([MPM4_BASE__Milestone1_Project__c].Go_Live_Date__c - DATE(1900,1,14),7)<5, [MPM4_BASE__Milestone1_Project__c].Go_Live_Date__c - 80,
(CASE(MOD( TODAY()- DATE(1900,1,14),7),
5, TODAY()+ 3,
6, TODAY()+ 2,
7, TODAY()+ 1,
TODAY() ) ))
Then I tried
CASE(MOD( MPM4_BASE__Project_Lookup__r.Go_Live_Date__c - DATE(1900,1,7),7),
0,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c-80),
1,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c-80),
2,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c-80),
3,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c-(80+2)),
4,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c-(80+2)),
5,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c-(80+2)),
6,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c-(80+1)),
MPM4_BASE__Project_Lookup__r.Go_Live_Date__c -80)
Please let me know what I am doing wrong? I entered 1/1/2019 as the Go Live Date and I still get 10/13/2018 ?
Thank you,
Dorel
(CASE(MOD( TODAY()- DATE(1900,1,14),7),
5, TODAY()+ 3,
6, TODAY()+ 2,
7, TODAY()+ 1,
TODAY() ) ))
Then I tried
CASE(MOD( MPM4_BASE__Project_Lookup__r.Go_Live_Date__c - DATE(1900,1,7),7),
0,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c-80),
1,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c-80),
2,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c-80),
3,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c-(80+2)),
4,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c-(80+2)),
5,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c-(80+2)),
6,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c-(80+1)),
MPM4_BASE__Project_Lookup__r.Go_Live_Date__c -80)
Please let me know what I am doing wrong? I entered 1/1/2019 as the Go Live Date and I still get 10/13/2018 ?
Thank you,
Dorel
You want to get: DATE2 = DATA1 - 80 business days (with 5 days par week)
80 business days (with 5 days per week) = 16 weeks x 7 = 112 days (with 7 days per week)
1) Adding Business Days to a Date:
This formula finds three business days from a given date ( but here the number of days is below five and seven, less than a week )
This formula finds the day of the week of the date field value. If the date is a Wednesday, Thursday, or Friday, the formula adds five calendar days (two weekend days, three weekdays) to the date to account for the weekend. If date is a Saturday, you need four additional calendar days. For any other day of the week (Sunday — Tuesday), simply add three days. You can easily modify this formula to add more or less business days. The tip for getting the day of the week might be useful if you need to adjust this formula.
https://help.salesforce.com/articleView?id=formula_examples_dates.htm&type=5
2) Subtracting a number of days from a date to find a past date without the week-ends:
http://people.albion.edu/imacinnes/calendar/Day_of_the_Week.html
MOD( DATE1 - DATE(1900,1,7),7) = 0 so DATE1 is the same day of 1/7/1900 = Sunday
All Answers
You want to get: DATE2 = DATA1 - 80 business days (with 5 days par week)
80 business days (with 5 days per week) = 16 weeks x 7 = 112 days (with 7 days per week)
1) Adding Business Days to a Date:
This formula finds three business days from a given date ( but here the number of days is below five and seven, less than a week )
This formula finds the day of the week of the date field value. If the date is a Wednesday, Thursday, or Friday, the formula adds five calendar days (two weekend days, three weekdays) to the date to account for the weekend. If date is a Saturday, you need four additional calendar days. For any other day of the week (Sunday — Tuesday), simply add three days. You can easily modify this formula to add more or less business days. The tip for getting the day of the week might be useful if you need to adjust this formula.
https://help.salesforce.com/articleView?id=formula_examples_dates.htm&type=5
2) Subtracting a number of days from a date to find a past date without the week-ends:
http://people.albion.edu/imacinnes/calendar/Day_of_the_Week.html
MOD( DATE1 - DATE(1900,1,7),7) = 0 so DATE1 is the same day of 1/7/1900 = Sunday
CASE(MOD( MPM4_BASE__Project_Lookup__r.Go_Live_Date__c - DATE(1900,1,7),7),
0,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c - 80 - 2 ),
1,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c - 80),
2,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c - 80),
3,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c - 80),
4,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c - 80),
5,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c - 80),
6,(MPM4_BASE__Project_Lookup__r.Go_Live_Date__c - 80 - 1 ),
MPM4_BASE__Project_Lookup__r.Go_Live_Date__c - 80)
In fact, you must use 112 days (including the week-ends) and not 80 opened days..
You just want 16 weeks before the reference date without the week-ends in the result.
The formula with 112 days works with complete weeks but it is a simplification because we can convert your 80 opened days in 16 complete weeks of 5 days each (or 16 complete weeks of 7 days and we just change the results for the days in week-ends (Saturday and Sunday)).
For example, if you want to subtract 8 opened days, it is a 1 weeks of 5 days + 3 days = 1 x 7 + 3 = 10 days
17 opened days, it is 3 weeks of 5 days + 2 days = 3 x 7 + 2 = 23 days
That is why the formula with 112 days is a simplification.
With 82 opened days, the formula would have been totally different.
There are many tricks like that used in these formulas with dates because that could be very complicated when you want a generic formula.
Salesforce doesn't provide this generic formula. You tried their formula and that doesn't work because it is not a generic formula.
The problem is that we cannot always write the generic formula because it would be too huge and there is a limit for the size of the compiled formula.
That could be possible to write the generic formula here but did you need to change the number of opened days very often?
It is more easy to change it manually after a small conversion towards a week of 7 days instead of a week of 5 days.
In fact, Salesforce has provided a precise algortihm but it is in Apex only.
The basic formula will be something like the formula below (not tested)
by replacing TODAY() with MPM4_BASE__Project_Lookup__r.Go_Live_Date__c
and Service_Lead_Days__c with 80 opened days directly He used 1/1/2000 instead of 1/7/1900 but you retrieve all the known tricks;
But it is an addition here and not a subtraction of opened days.
https://developer.salesforce.com/forums/?id=906F00000008wNHIAY
Replacing some "+" by "-" could be sufficient.
You want to substract 80 days including the week-ends or 80 opened days without the week-ends?
In fact, you will be always disapointed including using the formulas given by Salesforce (simplifications most of the time).
For the following questions, we have used a formula given by Salesforce for another problem: https://developer.salesforce.com/forums/?id=9060G000000XhyAQAS And we even tried formulas from other forums but there is always a case that doesn't work.
These formulas are often incomplete. They work most of the time but not for all the cases or they need to be much more complicated and you can exceed the limit for the size of a formula.
I am interested by these questions and that could be great to have the most precise formula at the end of your question including from people on other forums ( you can try other forums with the same question ).
Number of weeks x 7 - 1 day = 16 x 7 - 1 = 111
You can verify the number of days between two date without the week-ends with the folowing formula;
Monday + 1 day = Tuesday (morning) or end of Monday ?
Monday + 2 days = Wednesday
Monday + 3 day = Thursday
Monday + 4 days = Friday (so a week is only 4 days ?)
Monday: Go Live Date - 80 days
Tuesday:Go Live Date - 80 days
Wednesday: Go Live Date - 80 days
Thursday: Go Live Date - 80 days
Friday: Go Live Date - 80 days
Saturday: Go Live Date - 81 days
Sunday: Go Live Date - 82 days