+ Reply to Thread
Results 1 to 16 of 16

Back-Dating to get an earlier date which excludes Holidays and Week-Offs

  1. #1
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,522

    Back-Dating to get an earlier date which excludes Holidays and Week-Offs

    Back-Dating to get an earlier date which excludes Holidays and Week-Offs

    Dear Forum,

    I am in need of Back-Dating in order to make payments, I am generating dates for me to deposit the payments in a Bank/Finacial Institution/Lender, however the dates generated need to be "X" days in advance if they fall on any Holidays or Week-Offs..

    Now, there could be one or more Week-Offs for some Banks/Finacial Institutions/Lenders and not necessarily a Saturday and Sunday..so preferably it should be dynamic...

    There would also be some Public Holidays on which the Bank would be closed.

    Col A ----------------- Col B ----------------- Col C
    Sr.No ----------------- Public Holidays ----------------- Date
    1 ----------------- New Year's Day ----------------- 01-Jan-08
    2 ----------------- Good Friday ----------------- 21-Mar-08
    3 ----------------- Easter Monday ----------------- 24-Mar-08
    4 ----------------- Victoria Day ----------------- 19-May-08
    5 ----------------- Canada Day ----------------- 01-Jul-08
    6 ----------------- Labour Day ----------------- 01-Sep-08
    7 ----------------- Thanksgiving Day ----------------- 13-Oct-08
    8 ----------------- Remembrance Day ----------------- 11-Nov-08
    9 ----------------- Christmas ----------------- 25-Dec-08
    10 ----------------- Boxing Day ----------------- 31-Dec-08

    Lets say I Insert my date in F2 , G2 should contain the answer
    and the Week-Offs are mentioned in the cells D2 ,D3 and D4.

    D2--- WEEKLY-OFF 1----Tue
    D3--- WEEKLY-OFF 2----Wed
    D4--- WEEKLY-OFF 3----Thu.


    Ex:- F2=Original Date = 21-Mar-08 (Fri)

    The Date ( 21-Mar-08 Fri ) being a Holiday, the accurate answer considering there are no other Holidays earlier it should be (17-Mar-2008 Mon ) as there are 3 Week-Offs on Thursay,Wednesday and Tuesday.
    Last edited by e4excel; 02-06-2009 at 08:06 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Back-Dating to get an earlier date which excludes Holidays and Week-Offs

    I couldn't think of a good way to do this without having to double evaluate some part of the formula.... I also altered D:E such that E holds days one must offset should the result fall on the weekday specified in D (where 1 = Monday and 7 = Sunday)
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,522

    Re: Back-Dating to get an earlier date which excludes Holidays and Week-Offs

    Quote Originally Posted by DonkeyOte View Post
    I couldn't think of a good way to do this without having to double evaluate some part of the formula.... I also altered D:E such that E holds days one must offset should the result fall on the weekday specified in D (where 1 = Monday and 7 = Sunday)
    Splendid !

    But if I could just put the WeekDays like Tue,Wed,Thu instead of 1,2,3 etc...
    I dont know how to explain that but can we avoid using the helper columns and numeric weekdays..

    I am trying to use Name Defines

    1. WeekOFF = Query!$D$2:$D$8
    2. Holidays = Query!$C$2:$C$11

    Can you please incorporate the Names in your formula and also by WeekDays like Tue,Wed,Thu and no extra helper column if possible..

    The code does work but just a little personalisation...

    Thanks lot...
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: Back-Dating to get an earlier date which excludes Holidays and Week-Offs

    Quote Originally Posted by e4excel View Post
    Splendid !

    But if I could just put the WeekDays like Tue,Wed,Thu instead of 1,2,3 etc...
    I dont know how to explain that but can we avoid using the helper columns and numeric weekdays..

    I am trying to use Name Defines

    1. WeekOFF = Query!$D$2:$D$8
    2. Holidays = Query!$C$2:$C$11

    Can you please incorporate the Names in your formula and also by WeekDays like Tue,Wed,Thu and no extra helper column if possible..

    The code does work but just a little personalisation...

    Thanks lot...
    Try the following formula, which needs to be confirmed with CONTROL+SHIFT+ENTER...

    =LARGE(IF(ISNA(MATCH(F2-ROW(INDIRECT("1:10"))+1,C2:C11,0)),IF(ISNA(MATCH(TEXT(F2-ROW(INDIRECT("1:10"))+1,"ddd"),D2:D4,0)),F2-ROW(INDIRECT("1:10"))+1)),1)

    Hope this helps!

  5. #5
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,522

    Re: Back-Dating to get an earlier date which excludes Holidays and Week-Offs

    Quote Originally Posted by Domenic View Post
    Try the following formula, which needs to be confirmed with CONTROL+SHIFT+ENTER...

    =LARGE(IF(ISNA(MATCH(F2-ROW(INDIRECT("1:10"))+1,C2:C11,0)),IF(ISNA(MATCH(TEXT(F2-ROW(INDIRECT("1:10"))+1,"ddd"),D2:D3,0)),F2-ROW(INDIRECT("1:10"))+1)),1)

    Hope this helps!
    Excellent...! Domenic..

    Can you please explain the reason of having ROW(INDIRECT("1:10"))+1
    and then Im done...

    Lets say If I had to hard-code only one Week-Off then how do i do that?
    Like only single WeekOff="Sun"

    [ =LARGE(IF(ISNA(MATCH(E2-ROW(INDIRECT("1:10"))+1,Holidays,0)),IF(ISNA(MATCH(TEXT(E2-ROW(INDIRECT("1:10"))+1,"ddd"),???,0)),E2-ROW(INDIRECT("1:10"))+1)),1) ]

    Thanks a lot both of you Domenic as well as DonkeyOte...
    Have attached the file for reference..with both the solutions...
    Attached Files Attached Files
    Last edited by e4excel; 02-06-2009 at 07:35 AM. Reason: Forgot to add the Attachment

  6. #6
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: Back-Dating to get an earlier date which excludes Holidays and Week-Offs

    ROW(INDIRECT("1:10")) returns the following array of values...

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    Therefore, assuming that F2 contains 3/24/2008, F2-ROW(INDIRECT("1:10"))+1 returns the following array of values...

    3/24/08
    3/23/08
    3/22/08
    3/21/08
    3/20/08
    3/19/08
    3/18/08
    3/17/08
    3/16/08
    3/15/08

    Hope this helps!

  7. #7
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,522

    Smile Re: Back-Dating to get an earlier date which excludes Holidays and Week-Offs

    Dear Domenic,

    ROW(INDIRECT("1:10")) returns the following array of values...
    Got it...Thanks but no particular reason to keep it till 10...it will not change the result if it were any other number.


    Lets say If I had to hard-code only one Week-Off then how do i do that?
    Like only single WeekOff="Sun"

    [ =LARGE(IF(ISNA(MATCH(E2-ROW(INDIRECT("1:10"))+1,Holidays,0)),IF(ISNA(MATCH(TEXT(E2-ROW(INDIRECT("1:10"))+1,"ddd"),???,0)),E2-ROW(INDIRECT("1:10"))+1)),1) ]
    I tried it but did not get the answer, the reason of coming to the basic thing is as different banks would have different WeekOffs both in terms of Days as well as Numbers.

    In some earlier threads on queries on Dates, each day has some number assigned to it..Can that be used?

  8. #8
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: Back-Dating to get an earlier date which excludes Holidays and Week-Offs

    Quote Originally Posted by e4excel View Post
    Dear Domenic,



    Got it...Thanks but no particular reason to keep it till 10...it will not change the result if it were any other number.
    Well, you'll need to make sure that a large enough array is created. For example, if F2 (or I guess E2 now) contains 3/21/08, D2:D4 contains Tue, Wed, and Thur, and each instance of 10 is replaced with 3, the formula will return #NUM!.

    That's because E2-ROW(INDIRECT("1:3"))+1 creates the following array...

    21-Mar-08
    20-Mar-08
    19-Mar-08

    As you can see, none of the dates meets the criteria. The first date is a holiday and the next two are weekday-off's. As such, IF returns the following...

    FALSE
    FALSE
    FALSE

    Therefore, LARGE returns #NUM!.

    I tried it but did not get the answer, the reason of coming to the basic thing is as different banks would have different WeekOffs both in terms of Days as well as Numbers.

    In some earlier threads on queries on Dates, each day has some number assigned to it..Can that be used?
    Can you post a small sample of data, along with the expected results?

  9. #9
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,522

    Re: Back-Dating to get an earlier date which excludes Holidays and Week-Offs

    Quote Originally Posted by Domenic View Post
    Well, you'll need to make sure that a large enough array is created. For example, if F2 (or I guess E2 now) contains 3/21/08, D2:D4 contains Tue, Wed, and Thur, and each instance of 10 is replaced with 3, the formula will return #NUM!.

    That's because E2-ROW(INDIRECT("1:3"))+1 creates the following array...

    21-Mar-08
    20-Mar-08
    19-Mar-08

    As you can see, none of the dates meets the criteria. The first date is a holiday and the next two are weekday-off's. As such, IF returns the following...

    FALSE
    FALSE
    FALSE

    Therefore, LARGE returns #NUM!.

    Can you post a small sample of data, along with the expected results?
    So what I understand is to keep it as large a number as possible instead of less...

    I wish I could post a Sample but can right now as its not ready but I had the concept of picking the WeekOffs for different Banks..I need to gather the informatiion and tepmplatise that to use the magical formula...

    But wanted to know how do i go about Hard-coding for a Bank with a single WeekOff like a Sunday or Saturday ( Only One) ...Hardcoded in the formula...

  10. #10
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,522

    Re: Back-Dating to get an earlier date which excludes Holidays and Week-Offs

    Dominic,

    Your code works fabulously, there's no two minds about that..

    I mentioned as I would have different template models in my mind and in one of my ideas..What If I wanted to only hard code it for one Single Day such as a "Sun" for a generic solution and and an OFFSET NAME define code for some other situation...

    [ =LARGE(IF(ISNA(MATCH(E2-ROW(INDIRECT("1:10"))+1,Holidays,0)),IF(ISNA(MATCH(TEXT(E2-ROW(INDIRECT("1:10"))+1,"ddd"),"Sun",0)),E2-ROW(INDIRECT("1:10"))+1)),1) ]

  11. #11
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: Back-Dating to get an earlier date which excludes Holidays and Week-Offs

    Quote Originally Posted by e4excel View Post
    So what I understand is to keep it as large a number as possible instead of less...
    Actually, the larger the number, the greater the array. The greater the array, the more resource intensive the formula becomes. Based on your data, 10 seems reasonable.

    But wanted to know how do i go about Hard-coding for a Bank with a single WeekOff like a Sunday or Saturday ( Only One) ...Hardcoded in the formula...
    Try...

    =LARGE(IF(ISNA(MATCH(E2-ROW(INDIRECT("1:10"))+1,Holidays,0)),IF(TEXT(E2-ROW(INDIRECT("1:10"))+1,"ddd")<>"Sun",E2-ROW(INDIRECT("1:10"))+1)),1)

    Hope this helps!
    Last edited by Domenic; 02-06-2009 at 10:09 AM.

  12. #12
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,522

    Re: Back-Dating to get an earlier date which excludes Holidays and Week-Offs

    Dear Domenic

    Try replacing the reference with the following...

    {"Thu"}

    [ =LARGE(IF(ISNA(MATCH(E2-ROW(INDIRECT("1:10"))+1,Holidays,0)),IF(ISNA(MATCH(TEXT(E2-ROW(INDIRECT("1:10"))+1,"ddd"),"Thu",0)),E2-ROW(INDIRECT("1:10"))+1)),1) ]

    Hope this helps!
    No it doesnt work get a #NUM error...

  13. #13
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,522

    Re: Back-Dating to get an earlier date which excludes Holidays and Week-Offs

    Sorry my net speed is so slow that my message got posted after your solution but anyways wanted to tell you that i tried this both {[ = , <> ]} ...

    Ex: E2= 9-Feb-2009 (Mon)

    and 9-Feb-2009 is present in Holidays and there's only one weekoff which is Sunday ( 8-Feb-09) then the answer should be 7-Feb-09 Sat

    =LARGE(IF(ISNA(MATCH(E2-ROW(INDIRECT("1:10"))+1,Holidays,0)),IF(TEXT(E2-ROW(INDIRECT("1:10"))+1,"ddd")<>"Sun",E2-ROW(INDIRECT("1:10"))+1)),1)
    It gives the same answer 8-Feb-09 whereas the asnwer should be 7-Feb-09 Sat

  14. #14
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: Back-Dating to get an earlier date which excludes Holidays and Week-Offs

    The formula should return the desired result. Have a look at the attached file...
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,522

    Re: Back-Dating to get an earlier date which excludes Holidays and Week-Offs

    Hey Thanks a lot Domenic!

    I got it finally...ahd to actually scrutinise both the codes to understand the difference one is with MATCH and the other without...

    Thanks a million^million for hanging on till I got the solution....

  16. #16
    Forum Expert
    Join Date
    06-18-2004
    Location
    Canada
    MS-Off Ver
    Office 2016
    Posts
    1,474

    Re: Back-Dating to get an earlier date which excludes Holidays and Week-Offs

    You're very welcome!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1