• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 151
  • Last Modified:

Date Formula: Last business day - 2 of prior month

So I need two date formulas:

1. Calculate the third to last business day of the month (last business day - 2) of the PRIOR month.
2. Calculate the third to last business day of the month (last business day - 2) of the CURRENT month.
0
IO_Dork
Asked:
IO_Dork
  • 8
  • 8
2 Solutions
 
mlmccCommented:
Last Month
DateSerial(Year(CurrentDate), Month(CurrentDate), -2)

Open in new window


CurrentMonth
DateSerial(Year(CurrentDate), Month(CurrentDate)+1, -2)

Open in new window


mlmcc
0
 
IO_DorkAuthor Commented:
but does that handle just business days? or just any calendar day? Needs to calculate based on business days only.
0
 
mlmccCommented:
That is just calendar days.

I'll work on it for business days

mlmcc
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
James0628Commented:
Is "business days" just Mon - Fri, or something else?  Are holidays a factor?

 Since you didn't specify, I'm guessing that it's just Mon - Fri, but I thought I'd check.

 James
0
 
IO_DorkAuthor Commented:
Correct, Just mon - fri.
0
 
mlmccCommented:
DO you have the last day of the month available or do you need to calculate that?

mlmcc
0
 
IO_DorkAuthor Commented:
Need to calculate that
0
 
mlmccCommented:
Here is the basic formula for 3rd workday

WhilePrintingRecords;
If DayofWeek({Sheet2_.End Of Month}) in [1,2,3] then
    {Sheet2_.End Of Month} - 4
Else if DayofWeek({Sheet2_.End Of Month}) = 7 then
    {Sheet2_.End Of Month} - 3
Else
    {Sheet2_.End Of Month} - 2

Open in new window


mlmcc
0
 
mlmccCommented:
Updated to calculate last day of month based on current date

Name - Last Day Of Current Month
WhilePrintingRecords;
Local DateVar LastDay;
LastDay := DateSerial(Year(CurrentDate), Month(CurrentDate) + 1, 0);
If DayofWeek(LastDay ) in [1,2,3] then
   LastDay  - 4
Else if DayofWeek(LastDay ) = 7 then
    LastDay - 3
Else
    LastDay  - 2

Open in new window


Name - Last Day Of PreviousMonth
WhilePrintingRecords;
Local DateVar LastDay;
LastDay := DateSerial(Year(CurrentDate), Month(CurrentDate), 0);
If DayofWeek(LastDay ) in [1,2,3] then
    LastDay  - 4
Else if DayofWeek(LastDay ) = 7 then
    LastDay  - 3
Else
   LastDay  - 2

Open in new window


mlmcc
0
 
IO_DorkAuthor Commented:
mlmcc:

So I am trying to reference this field in another formula field and I get the following error...will it not be possible to reference the result of this formula field? Ultimately, I need to reference this field to conditionally sum a different field.

screenshot.png
0
 
mlmccCommented:
Take the WhilePrintingRecords line out of the formulas

mlmcc
0
 
IO_DorkAuthor Commented:
thanks, works perfectly!
0
 
IO_DorkAuthor Commented:
ok, so its been a few months since I accepted this solution, but now it does not seem to be working. I ran a report that brought back December 2016 records and the formulas were supposed to calculate the third to last business day of the current month and third to last day of prior month.

December 2016 should have been 12/27 because the last business day was 12/30  - but the formula returns 12/28.

November 2016 should have been 11/25 b/c the last business day was 11/30 and there was weekend in between - but formula returns 11/28.
0
 
mlmccCommented:
How are you figuring the dates?

By your definition above it is working

Dec 2016 - Last working day is 30 Dec 2016 - 2 days is 28 Dec 2016
Same for November.  Last working day is a Wednesday so 30 Nov 2016 - 2 is 28 Nov 2016
0
 
IO_DorkAuthor Commented:
right, I guess I mean 4 days before end of month....i was thinking 3 b/c take 12/27 and add 3days. so what part or parts of the formula should I change to return the 4th to last business day?
0
 
mlmccCommented:
Try this

WhilePrintingRecords;
Local DateVar LastDay;
LastDay := DateSerial(Year(CurrentDate), Month(CurrentDate), 0);
If DayofWeek(LastDay ) in [1,2,3,4] then
    LastDay  - 5
Else if DayofWeek(LastDay ) = 7 then
    LastDay  - 4
Else
   LastDay  - 3

Open in new window

1
 
IO_DorkAuthor Commented:
Thanks, those are the changes I figured would have to be done, but wasn't sure.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 8
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now