Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

Calculate Date of the week from weekending date

Posted on 2014-07-30
Medium Priority
228 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
Question by:spudmcc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions
7 Comments

LVL 40

Expert Comment

ID: 40229886
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
``````

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

LVL 27

Expert Comment

ID: 40229900
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 40

Expert Comment

ID: 40229904
Excel . . . sorry, thought this was SQL.
0

LVL 27

Accepted Solution

Glenn Ray earned 2000 total points
ID: 40229919
Example file attached with above formulas.
EE-DateLookup.xlsx
0

Author Closing Comment

ID: 40230569
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

ID: 40230671
I love helping folks save time!  That means there's time for dessert! :-)

-Glenn
0

LVL 50

Expert Comment

ID: 40249725
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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

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

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