# End of week from trading dates

Hi experts,

Here is a task in Excel. In column A, there is a list of trading days. We want to pick out the last day each week in the list and put those days in Column B. For a simple example, in the following list. They are trading days in January 2007.

1/3/2007
1/4/2007
1/5/2007
1/8/2007
1/9/2007
1/10/2007
1/11/2007
1/12/2007
1/16/2007
1/17/2007
1/18/2007
1/19/2007
1/22/2007
1/23/2007
1/24/2007
1/25/2007
1/26/2007
1/29/2007
1/30/2007
1/31/2007

And we want column B as:
1/5/2007
1/12/2007
1/19/2007
1/26/2007

The real data is much larger than one month. Is there a easy way to do it in formula?
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Microsoft Excel ExpertCommented:
here you go put this =A1+7-(WEEKDAY(A1)+1)
Microsoft Excel ExpertCommented:
see it in attached file
End-of-week-from-Date.xlsx
Commented:
You have a handful of options depending on how you want to process things and depending on what you mean by "end of week".

If "end of week" means Friday like the examples above, you can get this information from one of two formulas:

=TEXT(A1, "ddd") will return the three character shorthand for the day (e.g. "Fri")
=MOD(A1, 7) will return the remainder when dividing by 7 (e.g. 6, for Friday)

Option 1 is easier to understand; Option 2 is generally faster.

Either of those formulas could be copied down column B and used to filter for the Friday value.  If you just want the matching results, you can run a quick VBA through column A using either formula above to print results.  If you need updating formulas in column B which only return matching results, it can be done but gets a little fancy.  That formula would depend on ranges and be an array formula, but look something like this using the MOD approach above.

=SMALL(IF(MOD(A1:A27,7)=6, A1:A27, ""), ROW()-ROW(\$A\$1)+1)

If end of week means the "last day of this week of the dates provided", that can be done, but it gets even fancier.

Reply if those formulas are what you need and what final form is acceptable.
Microsoft Excel ExpertCommented:
ResourcefulDB

my formula does exactly as you have asked. please let me know.
Author Commented:
The Friday may be a holiday, such as July 4th, or January 1st. So, Friday may not always be the last trading day of the week.

In addition, in Column B, we just want the dates that are the end of week dates. A end of week date for each date from Column A is not what we wanted.

For example, in the January 2007 list, we just want 4 dates in column B.

Thanks for trying.
Microsoft Excel ExpertCommented:

now this is a new requirement you are asking for.

based on your original question the provided formula  =A1+7-(WEEKDAY(A1)+1)   does produce the result you have asked.
Commented:
If you can live with helper columns, this can be done the way you want.  The date is stored as a number.  When this number is divided by 7 and floored, you now have a "week number".  The idea then is to find the greatest dates present for each week present.

See the attached file for a solution.  This would probably be done much cleaner with VBA if that is acceptable.  If not, I think you are stuck with some helper columns.  At least, that's the best I can do.  You can always copy/paste values and delete the helper columns if that's OK.

Note that I have named the input dates "dates" and my helper column with week numbers "weeks".  This cleans up the formulas a bit.

Hopefully you can see how to modify this for your dates.  Note this assumes that "offending" dates will not be present in the input.  If they are there, then this really cannot be done.
Last-day-of-week-sample.xlsx
Author Commented:
@byronwall

Thank you. there is no problem of using helper column. I like your idea of getting the "week number" in column C and D. I wonder if Column D can handle the missing week, such as the following trading dates.

9/4/2001
9/5/2001
9/6/2001
9/7/2001
9/10/2001
9/17/2001
9/18/2001
9/19/2001
9/20/2001
9/21/2001
9/24/2001
9/25/2001
9/26/2001
9/27/2001
9/28/2001

Once we have the week number, then we can get the Friday of that week. Then arrange the original trading date in the ascending order and use vlookup to look for the date closest to the Friday of that week. It should be handle something like the following sequence.

7/1/2008
7/2/2008
7/3/2008
7/7/2008
7/8/2008
7/9/2008
7/10/2008
7/11/2008
7/14/2008
7/15/2008
7/16/2008
7/17/2008
7/18/2008
7/21/2008
7/22/2008
7/23/2008
7/24/2008
7/25/2008
7/28/2008
7/29/2008
7/30/2008
7/31/2008

See that July 4th was a Friday, but was not a trading date. But if we use vlookup to look for all the dates in this list that is approximate to 7/4/2008, it will give us 7/3/2008 and it is the last trading date of that week. Wanna go for it?

Thanks.
Commented:
It should already work as expected without having to do additional VLOOKUPs.  When I paste in the July dates you give, the spreadsheet outputs:

7/3/2008
7/11/2008
7/18/2008
7/25/2008
7/31/2008

in column B.  I believe this is what you are expecting for output?  For the September dates, it spits out:

9/7/2001
9/10/2001
9/21/2001
9/28/2001

which also appears correct.

The main thing now is expanding the formulas so that they cover the full range of inputs that you are expecting.  If you paste in the full range of dates for column A, you can then:
* fill columns B, C, and D down to the end of the data (B and D technically only need to go as far as the number of outputs, but you may as well drag them all the way down)
* update the named ranges "dates" and "weeks" to end at the correct row.

If you can make those changes, you are good to go.  If not, tell me how many inputs you have, and I will update it.  Or, alternatively, I can update the spreadsheet for 1000 or so inputs, and you can batch them in.

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Finance AnalystCommented:
Expanding on ByronWall's suggestion, using CEILING or FLOOR can round a date up or down to the last day of the week.

For example:
=CEILING(TODAY(),7)   gives 1 Nov 2014.

=FLOOR(TODAY(),7)     gives 25 Oct 2014

If you want to adjust to the Friday then just put -1 on the end.

The syntax for CEILING and FLOOR are:

=CEILING(Number,Factor)

Number - any number
Factor - the multiple to which you want to round.

With dates being stored as numbers and day 1 of the Excel calendar being 1 Jan 1900 which was a Sunday, every Saturday thereafter is a multiple of 7 so rounding up or down to a factor of 7 gives the Saturday date.

Combining this with a MATCH could then check for holidays and deducting a further day to return the Thursday if required.

=CEILING(TODAY(),7)-IF(ISERROR(MATCH(TODAY(),Holidays,0)),1,2)    Holidays = list of holiday dates

Thanks
Rob H
Finance AnalystCommented:
Looking at it again, putting this in column B against all dates would give a list of repeated dates which I don't believe you want. Therefore:

First entry in column B:

=CEILING(MIN(A:A),7)-IF(ISERROR(MATCH(MIN(A:A),Holidays,0)),1,2)    Holidays = list of holiday dates

Further entries in column B, if only one month at a time the most you will need is 5 in total; 1 as above and 4 of the following:

=IF(MONTH(B1+7)<>MONTH(B1),"",B1+7)

This will need tweaking to allow for holidays as well so I will take a look at that.

Thanks
Rob H
Finance AnalystCommented:
Slight tweak:

=CEILING(MIN(A:A),7)-IF(ISERROR(MATCH(CEILING(MIN(A:A),7)-1,Holidays,0)),1,2)

Thanks
Rob H
Finance AnalystCommented:
Tweaked first date calculation to allow for first of month being a Saturday:

=IF(WEEKDAY(MIN(A:A))=7,MIN(A:A)+6,CEILING(MIN(A:A),7)-IF(ISERROR(MATCH(CEILING(MIN(A:A),7)-1,Holidays,0)),1,2))

Tweaked subsequent date calculations:

=IF(MONTH(IF(ISERROR(MATCH(B1+7,Holidays,0)),CEILING(B1+7,7)-1,CEILING(B1+7,7)-2))>MONTH(B1),"",IF(ISERROR(MATCH(B1+7,Holidays,0)),CEILING(B1+7,7)-1,CEILING(B1+7,7)-2))

See attached, I have deliberately used April as Good Friday was a Holiday.

Thanks
Rob H
Friday-Dates.xlsx
Finance AnalystCommented:
Further tweak to first date calculation; in case first of month is Saturday AND following Friday is holiday:

=IF(WEEKDAY(MIN(A:A))=7,MIN(A:A)+IF(ISERROR(MATCH(MIN(A:A)+6,Holidays,0)),6,5),CEILING(MIN(A:A),7)-IF(ISERROR(MATCH(CEILING(MIN(A:A),7)-1,Holidays,0)),1,2))

Thanks
Rob H
Author Commented:
@byronwall,

Yes, I tested out your formula and it did give out nice results.

I notice that you use array formula in Column B, and find out the max of of all dates for the given week. that is very clever. it can be better than vlookup in this way

Thank you.
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.