I have a request where I am trying to determine if we hit our metrics with tickets opened to our company. Essentially we have to respond to cases within by the next business day, the exception here is if the ticket is opened after Friday 18:00 we get to wait till Tuesday end of day 18:00
So my original thinking was if a ticket:
1) a ticket is not opened, Fri, Sat, Sun then if response time is less than 24 then we MET
2) a ticket is opened up after 18:00 Friday then we have till EOD Tuesday 18:00 - it does not matter what time within Friday 18:00 to Sunday 23:59.
3) If a ticket is opened up Friday 00:00-117:59 then we have until Monday 18:00
Problem is I don't know how to calculate what the time should be, in a perfect situation a case is opened on Friday 17:00 and we have exactly 72 hours to respond. But cases are opened anytime throughout the weekend and how do I subtract that from the 72 to determine if we met or not.
Here is an example of my table
Month Year Day Time Hours Met/Miss
January 2017 Wed 15:20 19.77
January 2017 Tue 9:02 2.04
January 2017 Tue 11:35 0
January 2017 Fri 10:37 0.19
January 2017 Fri 17:48 89.06
January 2017 Mon 0:33 0.03
Any suggestions, I am also going to wrap this into VBA so that a macro does all this work.
Should know that I am only a beginner-intermediate in Excel and VBA - sorry
You're going to be better off if you can input your ticket open time as a date, then use a VBA function to calculate a due date. Then you can either calculate a ticket closed date and compare, or calculate a time difference and compare. Hypotheically you don't actually need your day of month because you only care about day of week, but it would be best to include day of month as shown below.
Edit
The same functionality of the VBA function below can be achieved by the worksheet equation:
=IF(WORKDAY(WORKDAY(H2,1,Holidays),-1,Holidays) = ROUNDDOWN(H2,0), WORKDAY(H2,IF(HOUR(H2)>=18,2,1),Holidays)+18/24, WORKDAY(WORKDAY(H2,-1,Holidays),2,Holidays) + 18/24)
Where the H column has ticket opened dates and Hol is your list of holidays.
It may or may not be easier/better to use this VBA function which basically does the same thing without holidays. The VBA function can be friendlier to future programming.
Function CalculateDueTime(OpenedTime As Date)
Dim DueTime As Date
Dim wkd As Integer
wkd = Weekday(OpenedTime, vbSunday)
If wkd = 1 Then
'Zero the hours, Add 2 days to get from Sunday to Tuesday, then get to 18:00
DueTime = DateAdd("h", 18, DateAdd("d", 2, DateAdd("h", -Hour(OpenedTime), OpenedTime)))
ElseIf wkd = 7 Then
'Zero the hours, Add 3 days to get from Saturday to Tuesday, then get to 18:00
DueTime = DateAdd("h", 18, DateAdd("d", 3, DateAdd("h", -Hour(OpenedTime), OpenedTime)))
Else
'Add an hours portion to see what day we arrive at
'The reason this works is because what you actually have is an offset in your end-of-day from midnight to EOB.
'So we're accounting for that offset by adding 6 hours then adding 24 to get to our due day,
'then defining 18:00 as our due time on that due day.
DueTime = DateAdd("h", 6 + 24, OpenedTime)
'Whatever day we arrived at above, zero the hours and add 18
DueTime = DateAdd("h", 18, DateAdd("h", -Hour(DueTime), DueTime))
wkd = Weekday(DueTime, vbSunday)
If wkd = 7 Or wkd = 1 Then
'If our due date lands on the weekend
'we can always resolve it by adding 2 days
'Opened Thur due Sat becomes due Mon
'Opened Friday due Sat becomes due Mon
'Opened Friday due Sunday becomes due Tues
DueTime = DateAdd("d", 2, DueTime)
End If
End If
CalculateDueTime = DueTime
End Function
This gives the the following results...
It doesn't really matter, but if you're curious about the date formatting here is the custom format I used.
Related
I need help assigning a group to specific times based on hour and day of the week.
So far I have
=LOOKUP(HOUR(C2),{0,2,6,16,18,23},{"LATENIGHT","OVERNIGHT","DAYTIME","FRINGE","PRIME","FRINGE"})
which is doing the job for Monday to Friday.
On weekends however I need
=LOOKUP(HOUR(C2),{0,2,6,18},{"LATENIGHT","OVERNIGHT","WEEKEND","PRIME"})
and I have no idea how to include an OR statement.
I have my days of the week on B2 using =TEXT(A2,"dddd") to reference my date column.
Data sample:
- May 22, 2020 Friday 6:45:56 AM DAYTIME
- May 22, 2020 Friday 4:15:56 PM FRINGE
- May 23, 2020 Saturday 10:15:56 AM DAYTIME (should be WEEKEND)
- May 24, 2020 Sunday 12:15:56 PM DAYTIME (should be WEEKEND)
- May 25, 2020 Monday 12:21:18 AM LATENIGHT
=IF(
WEEKDAY(C2,3)>4,
LOOKUP(
HOUR(C2),
{0,2,6,18},
{"LATENIGHT","OVERNIGHT","WEEKEND","PRIME"}
),
LOOKUP(
HOUR(C2),
{0,2,6,16,18,23},
{"LATENIGHT","OVERNIGHT","DAYTIME","FRINGE","PRIME","FRINGE"})
)
How can i start weeknum from first week in 2018 and go on through 2019, 2020, 2021, 2022... without starting the count from 1 every year. Ex: if 2018 has 44 weeks i want the weeknum(1-1-2019) to return 45 not 1 and so on.
If you Week starts on Monday use:
=INT((A1-"1/1/2018")/7)+1
If your week starts on Sunday:
=INT((A1-"1/1/2018"+1)/7)+1
I need to take the date from one cell, find the end of the month that that date falls into, then add one calendar month.
Example:
Enter jan 13: jan 13 end of month is Jan 31, + 1 month is Feb 28 (or 9 on leap year).
Feb 19: = March 31
March 2 = 30 April
March 30 = 30 April
March 31 = 30 April
etc etc
Is there an excel formula that will do this? I don't want any macro/ VBA stuff.
If you have 2007 or later than:
=EOMONTH("3/30/2016",1)
Use the Date function, add one to the month and set the Day to zero. This gives the last day of the month. To get the last day of the next month add two to the month.
=DATE(YEAR(E3),MONTH(E3)+1,0)
=DATE(YEAR(E3),MONTH(E3)+2,0)
I want to calculate the time difference between two dates with the following criteria:
1) excluding sundays and public holidays
2) TIMING: Mon to Fri = 7 AM to 7 PM &
Sat = 7 AM to 3 PM
I tried a many formulas and nothing works for me.
please any ideas??
Eg: Start Time: 3/6/2015 10:00 AM
End Time: 4/6/2015 12:00 PM
Then I should get the difference as 13 hrs (excluding time out of business hours)
If start and end "timestamps" will always be within working hours then you can use a formula like this:
=(SUM(NETWORKDAYS.INTL(A2,B2,{1,"1111101"},H$2:H$10)*{12,8})-IF(WEEKDAY(B2)=7,8,12))/24+MOD(B2,1)-MOD(A2,1)
Assuming start date/time in A2, end date/time in B2 and holiday list in H2:H10
Format result cell as [h]:mm and if start time is today (Monday) at 14:00 and end time is exactly a week later you will get the result 68:00 (5*12 hour days and 1*8 hour Saturday)
I would like to calculte the number of the week in a year. I see this post
In this post the acepted answer use this code:
public static int GetIso8601WeekOfYear(DateTime time)
{
// Seriously cheat. If its Monday, Tuesday or Wednesday, then it'll
// be the same week# as whatever Thursday, Friday or Saturday are,
// and we always get those right
DayOfWeek day = CultureInfo.InvariantCulture.Calendar.GetDayOfWeek(time);
if (day >= DayOfWeek.Monday && day <= DayOfWeek.Wednesday)
{
time = time.AddDays(3);
}
// Return the week of our adjusted day
return CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(time, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
}
However I see a problem. The number of the week is repeated if the last day of a month is in Sunday.
For example, the last day of March of 2013 year is in sunday. This week is the number 13th, is correct. But in April, how C# use always 6 weeks in a month to calculate the number of week, the first week of april has not any day of april, because all the days belong to march because the last day of the week is 30th March. So C# says that the first week of april is th 15th week, but this is incorrect, it has to be 14th.
So I would like to know if there are any way to calculate the number of a week in a right way.
EDIT:
I mean this:
In march, the last week is this:
25 26 27 28 29 30 31
This is the 13th, is correct.
In april, the first week is:
1 2 3 4 5 6 7
And this week is calculated as 15th.
So if I see the march calendar the last week is calculated as 13th and if I see the april calendar the last week of march is caluclated as 14th. This is incorrect.
SOLUTION:
DateTime dtCalendar = Calendar.DisplayDate;
int gridRow = (int)GetValue(Grid.RowProperty);
// Return the week of our adjusted day
int wueekNumber= System.Globalization.CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(dtCalendar, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday);
if (dtCalendar.DayOfWeek == DayOfWeek.Monday)
{
gridRow = gridRow - 1;
}
Text = (weekNumbe r+ gridRow - 1).ToString();
Thanks.
The problem is that you are using the wrong CalendarWeekRule. To get the result you want you should use FirstDay. I have seen various codes in internet saying that you should use FirstFourDayWeek but, after some testing, I realised that the "right one" is FirstDay. I have tested it with your example and it delivers the right result: 14th week.
int targetYear = 2013;
DateTime targetDate = new DateTime(targetYear, 4, 1);
int week = System.Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(targetDate, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday);