Excel Sumproduct not working when the condition time and date are put together? - excel

I have a worksheet that is a schedule, and I'm trying to create a graphical display [not chart] of how many people are working per hour window. Before I added the dates, which needed to be done so that shifts starting in the evening and going over midnight could be computed, it was working fine except for midnight shifts. The formula I was using is:
=SUMPRODUCT(F$53:F$67>=($C86+INT(F$5)),F$69:F$83<($D86+INT(F$5)))
Before the date addition, this was working fine[Except for the aforementioned problem]:
=SUMPRODUCT(F$53:F$67>=$C86,F$69:F$83
To where, $C86, is the start time 1-Feb 0:00, and $D86, is the end time 1-Feb 0:59. +INT(F$5) changes the date from 1-feb to an integer to be added to the hour time blocks. I also tried using COUNTIFS to no avail.
Screencap:
First off, is the way I am computing this possible? Secondly, is there a better way to do this? Thanks.

Related

Is a date within several date ranges

I'm trying to put together an excel spreadsheet to show the day-by-day impact of stays by 3rd country citizens in the EU's Schengen area (it's a fairly complex rolling 180 day window). At the moment, I have a column with every day from a start date (so lots of rows) and another where I enter a 1 if there was a stay in a Schengen country for that day. Then other columns calculate when the 180 day period started and how many days have been in Schengen for that day.
It's a bit of a faff having to enter a 1 for every day away. I'd like to have another worksheet where I simply enter the start and end dates of (an arbitrary number of) each stay and then the calculation spreadsheet simply works out if each date falls within a stay or not. Working out whether a date falls within one date range is pretty straightforward, but working out if it falls within several date ranges isn't obvious to me. Any suggestions please?
After a very fair comment, here's a couple of images that hopefully illustrate what I'm trying to do (please ignore the colours).
Example of date ranges, but the number of these should be arbitrary:
The calculated sheet - currently I have to enter the 1s individually whereas I'd like them evaluated from the date ranges:

Subtracting times across a day in excel

I am working on the capstone project in of the Google Career Certificate in Data Analytics. I am using Microsoft Excel. I have to calculate the ride length based on the start and end ride times. I've inputted the formula =F2(end time)-D2(start time) which returns the ride length. Going through my entire list I have some areas where the start time is like 11pm and the end time is 1am and this is returning ###### because it is a negative number with the regular formula. I've found a modified formula that can kind of do the conversion I am looking for but it is still a bit problematic. The modified formula is =(F2-D2+(F2<D2))*24 and it seems to give an accurate ride length if I reformat the answer to number. The issue is the rest of my data is in time format and the modified ones are in number format. If I convert the number values to time, the ride length values are inaccurate.
It is tricky to make the numeric value change as well due to me using a formula. I can correct them one by one after I save Excel and it no longer stores the numbers as the formula, but there are lots of data points to change and that would be time consuming. I'm hoping to find a more concise way to solve this problem. Maybe with a better formula.
[Snippet of the chart 1
Just like everything in life, there are multiple ways to achieve things. I would have formatted the date and time into a single cell; but. if you're gathering the data from another source, that's understandable.
A simple IF statement here will work. IF the days are one apart, then take '1' day off the starting time, else do your original formula:
=IF(E4-C4=1,F4-(D4-1),F4-D4)

Excel subtract X days from date and then find last specific workday date

here's my problem:
We have an Excel sheet at work in order to manage various tasks all set on individually specified timelines - we're talking hundreds of tasks per month with dates that are currently all being maintained manually.
Let's say we have Task A and that task has a Due Date. That Task is split into several subtasks, all with their individual due dates. Date 1 would then always be Due Date - 10 days, Date 2 would be Due Date - 20 days, Date 3 would be Due Date - 17 days and so on. This then creates a neat timeline of when everything needs to be done.
That in itself would be easy enough, problem is that all of these subtasks have to be done on a specific workday as well. Meaning that subtask 1 would not only have to be done Due Date - 10 days, but it would also have to fall on a Monday - if for whatever reason Due Date - 10 would happen to fall on like a Wednesday, it would have to subtract another 2 days. And then the real problem is that Date 2 and 3 each have to fall on different workdays and Task B has an entirely different schedule again.
Now, the first thing that came to my mind was attempting to just nest a couple IFs - and I've even managed to come up with a working formula for that. Problem here is that it's so stupidly long and (thanks Excel) utterly unreadable - if for some reason someone else had to change something about it or troubleshoot the entire file 1-2 years from now, they'd probably have to spend at least an hour reconstruct how the hell any of it actually worked. Which doesn't sound particularly appealing to us.
Here's a screenshot to help illustrating the situation:
And here's a draft of the current formula that I'm really not happy with, despite it somewhat doing the job:
=IF(AND(WEEKDAY(K2-VLOOKUP(B2,Table1,3,FALSE),11)>5,VLOOKUP(B2,Table1,5,FALSE)=0),(K2-VLOOKUP(B2,Table1,3,FALSE))-(WEEKDAY(K2-VLOOKUP(B2,Table1,3,FALSE),11)-5), IF(VLOOKUP(B2,Table1,5,FALSE)=0,K2-VLOOKUP(B2,Table1,3,FALSE), IF(WEEKDAY((K2-VLOOKUP(B2,Table1,3,FALSE)),11)=0,K2-VLOOKUP(B2,Table1,3,FALSE), (VLOOKUP(B2,Table1,5,FALSE)-WEEKDAY(K2-VLOOKUP(B2,Table1,3,FALSE),11))+K2-VLOOKUP(B2,Table1,3,FALSE))))
My question is now: Does anyone have an idea how to solve this in a less confusing and unclear manner? I was trying to get something done using =CHOOSE() but ultimately ended up with the same problem of eventually having to resort to 7 IFs and dozens of LOOKUPs, making the final formula just as long. I wouldn't be disinclined towards some kind of helper table that asigns the last 7 days and their workdays to every single day of the year... but I don't think tossing another 20,000 calculated cells into a file that already has tens of thousands other calculated cells would really be a serviceable alternative... or make the situation any less obscure at all tbh.
So, anyone any idea how to go about this? Or is there really no realistic alternative than to use a bunch of IFs?
Edit: Forgot to mention that 1 special case:
There's also the situation when a date doesn't have to fall on a specific workday - in which case it's simply due date - X days. The problem here is that in those cases the dates could fall on a weekend, so the formula would have to move these dates to the previous Friday as well.
Assume you have some date and you want to "back up" ten days and then to the preceding Monday, unless the resultant date is a Monday. The general formula would be something like:
=A2-10+1-WEEKDAY(A2-10-DOW)
Where DOW translates into
Sunday=0
Monday=1
Tuesday=2
...
You should be able to modify your formulas to use this algorithm for day of the week.
If the two tables are named thisTable and keyTable, the following 365 formula is one way of implementing:
If your tables are as below, you can enter the formula in B2 and fill down and across. The references should self-adjust and return the proper dates.
Note that in keyTable, I enter the day of the week DOW as defined above, and not the textual date.
=LET(dys,VLOOKUP(thisTable[#[Task]:[Task]],KeyTable,COLUMNS($A:A)*2,FALSE),
dow,VLOOKUP(thisTable[#[Task]:{Task]],KeyTable,COLUMNS($A:A)*2+1,FALSE),
due,thisTable[#[DueDate]:[DueDate]],
IF(dow="flexible",WORKDAY(due-dys+1,-1),due-dys+1-WEEKDAY(due-dys-dow)))
If you want to have the result be the closest workday, instead of the preceding workday, then you need to add two clauses to the LET function
Calculate the subsequent workday date
Then use an IF to return the closest one to the original target
eg:
=LET(dys,VLOOKUP(thisTable[#[Task]:[Task]],KeyTable,COLUMNS($A:A)*2,FALSE),
dow,VLOOKUP(thisTable[#[Task]:[Task]],KeyTable,COLUMNS($A:A)*2+1,FALSE),
due,thisTable[#[DueDate]:[DueDate]],
dayPrev,IF(dow="flexible",WORKDAY(due-dys+1,-1),due-dys+1-WEEKDAY(due-dys-dow)),
daySubseq,IF(dow="flexible",WORKDAY(due-dys+1,-1),due-dys+7-WEEKDAY(due-dys-1-dow)),
IF((daySubseq-due+dys)>3,dayPrev,daySubseq))

Number of minutes in a time range - EXCEL

I have a sheet for tracking my hours at work. We also have a time period between the hours of 07:30 & 18:00 where we can accrue 'flex time'. I want to know from my in and out times, how many hours:minutes I have made in flex.
Please can someone help with the calculation?
The standard way of doing these is to use the overlap formula for two intervals
=max(0,min(end1,end2)-max(start1,start2))
So in your case it would be
=MAX(0,MIN(C2,TIMEVALUE("18:00"))-MAX(B2,TIMEVALUE("7:30")))
If some of your time cells contain strings instead of numbers you would need to check for these. One way of doing it is
=IFERROR(MAX(0,MIN(C2+0,TIMEVALUE("18:00"))-MAX(B2+0,TIMEVALUE("7:30"))),0)
If you ever did a night shift including midnight the formula would need further modification.
Fixed my formula to get correct answers. Bit odd but works now!
=C4+IF(A4-TIME(7,30,0)<0,A4-TIME(7,30,0),0)-IF(B4-TIME(18,0,0)>0,B4-TIME(18,0,0),0)
We take the total time then
if our time starts earlier than flex time starts, we ADD the difference between our start time and flex time, which of course will be a negative number
if our end time ends later than flex time ends, we SUBTRACT the difference between our end time and flex time

Select pay rate based on day and shift start time

Im creating an excel pay sheet so i can keep tabs on my pay.
I have two pay rates,
£9.30 is paid for hours worked from 6pm to 8am Monday to Thursday
£10.30 is paid for hours worked from 6pm Friday to 8am Monday.
I have a column that displays the pay rate, i want this to populate automatically with excel looking at the day of the week and then the start time and then returning the correct pay rate.
For example,
If the day is a Mon and the start time is 6pm return £9.30
If the day is Fri and the start time is 6pm return £10.30 etc etc
Any one have any ideas on how i can achieve this? Id rather this be formula based instead of VBA if possible but if it cant be formula based then VBA it is.
Thanks in advance
I had to make a few assumptions because your question was unclear about the possible start times for your shifts. Your wording and examples lead me to believe that your shifts always begin at 6 PM regardless of the day. I created a possible solution or start to a solution based on that assumption that does not rely on VBA. I've included links to an excel workbook with my solution and a screen shot. (I'm only allowed 2 links with my current rep.)
As Gowtham Shiva suggested in the comments, a screen shot of what you have so far would be helpful.
I created two tables and a named ranged called “valDays”. To use the workbook, you enter the date and start time for your shift in tblPay. Enter the pay rate for a specific day and time in tblRates. valDays provides a way to convert the text for a day of the week into a number for calculating date/time serial numbers.
Feel free to comment/message me for clarification. I’ll do my best to reply and refine the solution as necessary. I hope you find this answer helpful and appreciate feedback. This is my first time providing an answer on Stack Overflow.
I’m going to assume you know how to name a range, create tables, and rename tables in excel. If you don’t there are plenty of YouTubers and bloggers that cover these topics quite well.
List the days in a column off to the right. (I used column K.) “Sun”, “Mon”, “Tue”, etc. Select all the cells with the days of the week and name the range “valDays”.
Formula in tblRates[Serial]:
“=MATCH(tblRates[[#This Row],[Day]],valDays,0)+tblRates[[#This Row],[Time]]”
Formula in tblPay[Serial]:
“=WEEKDAY([Date])+[StartTime]”
Formula in tblPay[Rate]:
“=INDEX(tblRates[Rate],MATCH([Serial],tblRates[Serial],0))”
You can download the excel document and view these screenshots of a possible solution.
Link to Excel Workbook on Google Drive
Screenshot1

Resources