I have a list of date timestamps and if any of the times happen outside of our working hours, I need to advance them forward to the start of the next workday.
Our work hours are M-F 8:30am-5:30pm, Saturday 8:30am-1:30pm, Sunday closed and we are also closed on holidays.
Examples:
Friday June 26, 2020 6:30pm should be advanced to Saturday June 27, 2020 8:30am
Friday July 3, 2020 6:30pm should be advanced to Monday July 6, 2020 8:30am. Because Saturday was a holiday and we are closed on Sunday.
Friday July 3, 2020 5:29pm should not be advanced because it began during work hours
Column A |Column B | Column C | Column B | Column E
Underwriter | LoanNumber | EntryTime_+3hrs | Desired Outcome | HOLIDAY
TOM | 1 | 07/31/2020 8:28:42 AM | 08/01/2020 8:30:00 AM | 01/01/2020
DICK | 2 | 07/30/2020 6:32:36 PM | 07/31/2020 8:30:00 AM | 01/20/2020
JANE | 3 | 07/30/2020 4:18:57 PM | 07/30/2020 4:18:57 PM | 02/17/2020
BETH | 4 | 07/30/2020 3:06:18 AM | 07/30/2020 8:30:00 AM | 05/25/2020
SALLY | 5 | 07/29/2020 6:35:37 PM | 07/30/2020 8:30:00 AM | 07/04/2020
GEORGE | 6 | 07/03/2020 7:45:26 PM | 07/06/2020 8:30:00 AM | 09/07/2020
| | | | 10/12/2020
| | | | 11/11/2020
| | | | 11/26/2020
| | | | 12/24/2020
| | | | 12/25/2020
Start date time stamps need to be validate and converted to next available time slot.
Current thinking is you have three potential outcomes:
The date will need to be shifted next possible day starting at 0830
The date will remain the same but the time will be shifted to 0830
The date and time are valid and no adjustment is required.
so a generic formula might look something like this:
IF(OR(HOLIDAY,SUNDAY,AFTERHOURS),FIND NEXT WORKDAY,
IF(BEFORE WORKHOURS, SET TIME TO START TIME, ITS VALID TIME))
In order to check each condition individually for a potential day shift we can use the following formulas:
(ASSUME C2 is the start date being tested)
WEEKDAY AFTER 1730
=AND(MOD(C2,1)>TIME(17,30,0),OR(WEEKDAY(C2)={2,3,4,5,6}))
SATURDAY AFTER 1330
=AND(MOD(C2,1)>TIME(13,30,0),WEEKDAY(C2)=7)
HOLIDAY (list in E2:E12)
=COUNTIF($E$2:$E$12,INT(C2))=1
SUNDAY
=WEEKDAY(C2)=1
The MOD function in the first two formulas is stripping the Integer/date value and just keeping the decimal/time portion
The { } is a manual list/array is a nice way of doing multiple OR checks with out writing out each individual check. Since these are sequential, you do have other options.
Now there is a way of flagging each case, So now just rearrange and group together so you have three choices in a nested IF function:
=IF(OR(AND(MOD(C2,1)>TIME(17,30,0),OR(WEEKDAY(C2)={2,3,4,5,6})),AND(MOD(C2,1)>TIME(13,30,0),WEEKDAY(C2)=7), COUNTIF($E$2:$E$12,INT(C2))=1, WEEKDAY(C2)=1), FIND NEXT DATE, IF(BEFORE WORK, SET TIME TO 0830, DO NOTHING))
Since each valid day starts at 0830 and invalid days have already been taken care of with the first IF, only the start time needs to be checked.
=MOD(C2,1)<TIME(08,30,00)
And the valid time is the only case left over so there is nothing to check for.
And you pseudo formula becomes something like:
=IF(OR(AND(MOD(C2,1)>TIME(17,30,0),OR(WEEKDAY(C2)={2,3,4,5,6})),AND(MOD(C2,1)>TIME(13,30,0),WEEKDAY(C2)=7), COUNTIF($E$2:$E$12,INT(C2))=1, WEEKDAY(C2)=1), FIND NEXT DATE, IF(MOD(C2,1)<TIME(08,30,00), SET TIME TO 0830, DO NOTHING))
So now you just need to figure out how to add some days, change the time, and keep what you have for a value.
Adjusting the number of days to add had me looking at multiple nested IF equal to the number of days in a row that could be invalid. Right now I have the worst case scenario being Thursday at 17:31 something starts. Friday is a holiday as a result of a holiday on Saturday, Sunday is a holiday, and Monday is a holiday due to the Sunday holiday. So first potential day would be 5 days away. Ugly nested IF. As an alternative I looked at AGGREGATE and adding 1 day at a time up to 5 and checking if its a valid date. Then take the lowest/earliest date and setting start time to 0830. To achieve this I tried the following formula:
=AGGREGATE(15,6,(INT(C2)+{1,2,3,4,5})/((COUNTIF($E$2:$E$12,(INT(C2)+{1,2,3,4,5}))<1)*(WEEKDAY(C2+{1,2,3,4,5})<>1)),1)+TIME(8,30,0)
Then next function you need to do is keep the date but set the time to 08:30
=INT(C2)+TIME(08,30,00)
and your do nothing is:
=C2
so now if we combine the crap out of that into one formula we wind up with:
=IF(OR(AND(MOD(C2,1)>TIME(17,30,0),OR(WEEKDAY(C2)={2,3,4,5,6})),AND(MOD(C2,1)>TIME(13,30,0),WEEKDAY(C2)=7), COUNTIF($E$2:$E$12,INT(C2))=1, WEEKDAY(C2)=1), AGGREGATE(15,6,(INT(C2)+{1,2,3,4,5})/((COUNTIF($E$2:$E$12,(INT(C2)+{1,2,3,4,5}))<1)*(WEEKDAY(C2+{1,2,3,4,5})<>1)),1)+TIME(8,30,0), IF(MOD(C2,1)<TIME(08,30,00), INT(C2)+TIME(08,30,00), C2))
I believe the desired date in D2 (red background) is wrong and should instead be 20/07/31 08:30
reference to your previous question
Now in theory this could be substituted for every B2 reference in the first formula, but A) the thing would become even more damned unreadable and hard to maintain than it already is, and B) may cause multiple repetitive calculations.
everyone. I am trying to get the difference between two dates in Excel based on a defined deadline which is the 10th the following month. Please see sample below.
Month | Deadline | Date Paid | Month/s Elapsed | Remarks
Jan 2020 | Feb. 10, 2020 | Feb. 10, 2020 | 1 | One 10th has passed
Jan 2020 | Feb. 10, 2020 | Mar. 13, 2020 | 2 | Two 10th have passed based on Date Paid
Mar 2020 | Apr. 10, 2020 | Jun. 27, 2020 | 3 | Three 10th have passed from Mar 2020 - June 27, 2020
Basically, should the Date Paid fall beyond the 10th of the following month, it should count how many 10ths have elapsed from the deadline to the date paid. Here is my formula so far and it's not taking into account the deadline which is the 10th every month.
=MONTH(c2)-MONTH(B2)
Could you kindly provide any ideas as to how I can achieve the expected output?
I hope my question is clear. Thank you in advance for your help.
In your current setup it looks like you could just use:
=DATEDIF(B2,C2,"M")+1
Not sure if that would be error-proof for all your cases. The following should return the amount of dates in an array that are equal to the 10th of that month:
=SUMPRODUCT(--(DAY(ROW(INDEX(A:A,A2):INDEX(A:A,C2))=10))
This is with the assumption that column A holds dates that are the last days of those months!
I have a table where each row represents one logical value.
Sort of like this:
| January | Margaret | 10 |
| February | Jeff | 20 |
| March | William | 30 |
I want to transfer the data to another table, where the data would be modelled as following:
| | January | February | March
+----------+---------+----------+------
| Margaret | 10 | |
| Jeff | | 20 |
| William | | | 30
In the case of changes in the Table 1 same changes should be reflected in the Table 2
There are only 4 names and 12 months. Names are repeated A,B,C,D,A,B,C,D,A,B,C,D.
Numbers are 10-120. Obviously I can use = and click on the cell in the first table but I need more optimal solution. I can't figure it out. Any advise would be much appreciated!
It sounds like what you're trying to do is called a long to wide transformation. In this case, since you just have months, it might be easiest to create a table with your months as headers (i.e. January - December), and then write a INDEX/MATCH formula to fill it in.
Let's say this is your table, starting in cell A2
Date Name Value
January Jone 1
January Mike 2
January Bob 3
February Jone 4
February Mike 5
February Bob 6
Then create a table with a header row for the months, starting in B10
January February March April May June July August September October November December
And a column for the unique names, starting in A11
Jone
Mike
Bob
So the whole thing looks like this:
January February March ...
Jone
Mike
Bob
Then we use an INDEX/MATCH formula to fill in the table. Write this in cell B11, then fill down and across:
=INDEX($C$3:$C$8,MATCH(1, INDEX(($A11=$B$3:$B$8)*(B$10=$A$3:$A$8),0,1),0))
This says, return a value from C3:C8 where both A11 and B10 match in their respective ranges B3:B8 and A3:A8.
You end up with:
January February ...
Jone 1 4
Mike 2 5
Bob 3 6
You can use Get&Transform to
Pivot Column 1
Advanced Options: Don't Aggregate
Values Column: Column 3
I have a table of data that has a format similar to the following:
EventID | Event Date
--------------------
1 | 1/1/2014
2 | 2/8/2014
3 | 10/1/2014
4 | 2/5/2014
5 | 4/1/2014
6 | 9/1/2014
What I am trying to do is create a DAX formula to rank each event in the order that it happened for the year. So I want to end up with something like this. This way I can compare the events year over year as the events don't happen on any regular time schedule.
Event Date | Year | Rank
------------------------
1/1/2014 | 2014 | 1
2/8/2014 | 2014 | 2
10/1/2014 | 2014 | 3
2/5/2015 | 2015 | 1
4/1/2015 | 2015 | 2
9/1/2015 | 2015 | 3
I have tried to do this by creating a formula that will give me the day number of the year:
Day of Year =(YEARFRAC(CONCATENATE("Jan 1 ", YEAR([Event Date])),[Event Date])*360)+1
Then using rankX on this table, but I cant seem to get the proper result. Perhaps I am not understanding the use of rankX or going about this the right way.
=RANKX(FILTER(Event,EARLIER(Event[Event Year])=Event[Event Year]),Event[Day of Year])
or
=RANKX(All(Event[Event Year]),[Day of Year],,1,Dense)
Any ideas would be much appreciated!
Thanks for any help in advance!
Create the following measures:
[Year]:=YEAR(LASTDATE(Event[Event Date]))
and
[Rank]:=RANKX(FILTER(ALL(Event),[Year]=YEAR(MAX(Event[Event Date]))),FIRSTDATE(Event[Event Date]),,1,DENSE)
and this is the result that you get:
Note: My dates are in UK format and I suspect yours were in US format, so the rankings do not appear to tally with your example, but it does work!