Solved

Calculate Date of the week from weekending date

Posted on 2014-07-30
7
207 Views
Last Modified: 2014-08-08
Hi Experts!

I have a weekending date (Sunday) in column A.  I have the day of the week name in column B.  What I need in column C is the date associated for that day of the week.  

7/27/14     Mon    7/21/14
7/27/14     Tue     7/22/14
7/27/14     Wed    7/23/14
7/27/14     Thu     7/24/14
7/27/14     Fri       7/25/14
7/27/14     Sat      7/26/14
7/27/14     Sun     7/27/14

Of course I have different weekending dates in a huge data set.  It is column c that I am trying to populate.

Any help would be greatly appreciated.
0
Comment
Question by:spudmcc
7 Comments
 
LVL 39

Expert Comment

by:Kyle Abrahams
Comment Utility
I would create a function:

create function GetDateAdj
( @weekday varchar(3) 
)
returns int
as
begin 
   declare @adjust int
   select @adjust = case @weekday
      when 'Sun' then 0
      when 'Sat' then -1
      when 'Fri' then -2
      when 'Thu' then -3
      when 'Wed' then -4
      when 'Tue' then -5
      when 'Mon' then -6

return (@adjust)
end

Open in new window


then select [A], [ B], dateadd(d, [A], dbo.GetDateAdj([ B])) as C
0
 
LVL 27

Expert Comment

by:Glenn Ray
Comment Utility
Here are a few possible solutions:

1) Enter this formula in cell C1 and copy down:
=A1-MATCH(B1,{"Sun","Sat","Fri","Thu","Wed","Tue","Mon"},0)+1

2) Create named range ("DayList" for example) with this set of values:
={"Sun","Sat","Fri","Thu","Wed","Tue","Mon"}
then enter this formula in cell C1 and copy down:
=A1-MATCH(B1,DayList,0)+1

3) Create an actual vertical range of values anywhere in your workbook,
Sun
Sat
Fri
Thu
Wed
Tue
Mon
Highlight and name this range (again, "DayList" as an example), then use the same formula as shown in 2).

-Glenn
0
 
LVL 39

Expert Comment

by:Kyle Abrahams
Comment Utility
Excel . . . sorry, thought this was SQL.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 27

Accepted Solution

by:
Glenn Ray earned 500 total points
Comment Utility
Example file attached with above formulas.
EE-DateLookup.xlsx
0
 

Author Closing Comment

by:spudmcc
Comment Utility
Awesome solution.  This is going to save a huge amount of time and frustration.  I so very much appreciate sharing your knowledge and time addressing this issue for me.

Much thanks!

Andy
0
 
LVL 27

Expert Comment

by:Glenn Ray
Comment Utility
I love helping folks save time!  That means there's time for dessert! :-)

-Glenn
0
 
LVL 50

Expert Comment

by:barry houdini
Comment Utility
Wouldn't it be sufficient just to make C7 equal to A7 and then count back one day at a time? So that would mean just this formula in C7

=A7

and then this formula in A6 copied up

=A7-1

regards, barry
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now