Calculating Business Days in Excel/Indirect Reference - excel

I'm working on making a spreadsheet where someone can put in a date they want a final product by, and then it will automatically fill out deadlines for different steps along the way. (i.e.) If you want something by June 22, Step C would need to be done x business days prior, Step B would need to be done y business days prior to that, and Step A z business days prior to that.
This definitely isn't the best way to do it but I think it should be okay for now because this is only needed for a finite time, I wrote out a list of all the business days in the relevant time frame. I want to make it so when someone types in the day they need the final product, the dates before it fill out just by inputting the cell x cells before the final date, etc.
If there's a better/easier way to do this I'm all ears. This is just what I was thinking as someone with not all that much Excel experience who just needs to make this functional, not perfect.

Related

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))

Need proper formula to obtain correct value

It's my first question here. I need a formula which take the correct code at specific date. After taking correct code, excel table is using it for calculation of the correct value.
The concept is a little complicated. There is a calendar which is starting at 15.09.2021 (V3 Cell) and ending at 04.06.2022(JX3 Cell). And our codes are: ITB, OR, TBE, CBE, PO, VDR, SMF, FMF and DS. All of them are the steps of procurement process. And each of them has a specific values/coefficients like 0.1, 0.2, 0.15 etc and everyone comes true at specific date. And their locations are L2 to T2.
For example, we are taking the codes for procurement of generator at 15 September 2021:
=IF(V$3=$L5;$L$2;IF(V$3=$M5;$M$2;IF(V$3=$N5;$N$2;IF(V$3=$O5;$O$2;IF(V$3=$P5;$P$2;IF(V$3=$T5;$T$2;IF(V$3=$S5;$S$2;IF(V$3=$R5;$R$2;IF(V$3=$Q5;$Q$2;0)))))))))
L5 to T5 are the dates of procurement steps of that item.
And we are using same formula for other dates. It is working. But when, for example TBE and CBE completed at the same day, excel takes one of them (which is first). Sometimes 4-5 steps are completing at the same day. And for this situation, we can not take the true value of the item's procurement. We are calculating the progress of the procurement in that way. But as I said, it isn't working for the same dates. I tried to fix the formula by putting all possible combinations and giving them new code and coeffient:
=IF(AND(V$3=L5;V$3=M5;V$3=N5;V$3=O5;V$3=P5;V$3=Q5;V$3=R5;V$3=S5;V$3=T5);$U$117;IF(AND(V$3=L5;V$3=M5;V$3=N5;V$3=O5;V$3=P5;V$3=Q5;V$3=R5;V$3=S5);$U$118;IF(AND(V$3=L5;V$3=M5;V$3=N5;V$3=O5;V$3=P5;V$3=Q5;V$3=R5);$U$119;IF(AND(V$3=L5;V$3=M5;V$3=N5;V$3=O5;V$3=P5;V$3=Q5);$U$120;IF(AND(V$3=L5;V$3=M5;V$3=N5;V$3=O5;V$3=P5);$U$121;IF(AND(V$3=L5;V$3=M5;V$3=N5;V$3=O5);$U$122;IF(AND(V$3=L5;V$3=M5;V$3=N5);$U$123;IF(AND(V$3=L5;V$3=M5);$U$124;IF(AND(V$3=M5;V$3=N5;V$3=O5;V$3=P5;V$3=Q5;V$3=R5;V$3=S5;V$3=T5);$U$125;IF(AND(V$3=M5;V$3=N5;V$3=O5;V$3=P5;V$3=Q5;V$3=R5;V$3=S5);$U$126;IF(AND(V$3=M5;V$3=N5;V$3=O5;V$3=P5;V$3=Q5;V$3=R5);$U$127;IF(AND(V$3=M5;V$3=N5;V$3=O5;V$3=P5;V$3=Q5);$U$128;IF(AND(V$3=M5;V$3=N5;V$3=O5;V$3=P5;V$3=Q5);$U$129;IF(AND(V$3=M5;V$3=N5;V$3=O5;V$3=P5);$U$130;IF(AND(V$3=M5;V$3=N5;V$3=O5);$U$131;IF(AND(V$3=R5;V$3=N5;V$3=O5;V$3=P5;V$3=Q5;V$3=S5;V$3=T5);$U$132;IF(AND(V$3=R5;V$3=N5;V$3=O5;V$3=P5;V$3=Q5;V$3=S5);$U$133;IF(AND(V$3=R5;V$3=N5;V$3=O5;V$3=P5;V$3=Q5);$U$134;IF(AND(V$3=N5;V$3=O5;V$3=P5);$U$136;IF(V$3=$L5;$L$2;IF(V$3=$M5;$M$2;IF(V$3=$N5;$N$2;IF(V$3=$O5;$O$2;IF(V$3=$P5;$P$2;IF(V$3=$T5;$T$2;IF(V$3=$S5;$S$2;IF(V$3=$R5;$R$2;IF(V$3=$Q5;$Q$2;0))))))))))))))))))))))))))))
New codes are at U117 to u152.
As it can be seen, it is so rough method to use. I tried to put every possible combination but also there is a character limit and i can't write all of them too.
I hope I could explain the problem well. Maybe it can be solved by VBA too.
I'll be glad if anyone helps for practical methods. Thanks.

How to pull a random object from a list and remove it in Excel?

I'm trying to create a rotational schedule in Excel that will randomly assign a building once a week without duplicates. I need each building to have a morning/afternoon shift and alternate the following week.
So what I was thinking is there are 20 shifts every 2 weeks, Morning/Afternoon 5 days a week and I have 10 buildings to go to so that works out nicely. I want it to be random so that way I am not always in the same building at the same time every week.
So I used =RAND() in Column B of sheet 1 to generate a random number for each building and then pasted it as just values to get rid of the formula in that column.
Then on sheet 2, I tried having =INDEX(Sheet1!$A$2:$A$11, RANDBETWEEN(1,COUNTA(Sheet1!$B$2:$B$11))) in each cell of 5x4 schedule.
The problem is there are duplicates and I want the second week to actually be opposite morning/afternoon but still random days. I think that I'll probably have to have it randomize morning/afternoon the first week, then do days and the second week have it opposite whatever the random morning/afternoon was and then do random days again but I'm just not sure how to go about it.
I'm new to programming in Excel and my programming is a little rusty in general...
EDIT: I was able to use =CHOOSE(RANDBETWEEN(1,2),"Morning","Afternoon") to have a column choose morning/afternoon randomly but it doesn't ensure equal number of mornings to afternoons which I need. And I still wouldn't know how to have the opposite results elsewhere for the following week.
I think you can use if condition to make sure you select opposite morning/afternoon after you selected random days.
like this:
=IF(AND(B3="Morning",C3="Morning"),"Afternoon",IF(AND(B3="Afternoon",C3="Afternoon"),"Morning",C3))

Excel - Finding nth day of specific month from any day of the year

I'm creating a daily scheduling report. Not every position in the report has to be staffed every day, but there's rules determining this (daylight savings mostly) and I've been pulling my hair out trying to figure out a good way to do this that will make it anyone-proof for the person that needs to fill out the sheet on any given day.
My issue: Starting the first sunday in november, one position doesn't need to be staffed all the time. This continues until the second sunday in march. I want the box that shows this position to be conditionally formatted based on what today's date is (which is shown in E1 using =Today() )
I got something close to working (though it looks disgusting), and would cite sources, but I just came back to working on this project after a couple months of a different assignment:
=IF(MONTH(E1)>10,AND((DATE(YEAR(E1),11,1+7*1)-WEEKDAY((DATE(YEAR(E1),11,8-1))))<E1,E1<(DATE(YEAR(E1)+1,3,1+14*1)-WEEKDAY((DATE(YEAR(E1)+1,3,8-1))))),AND(DATE(YEAR((DATE(YEAR(E1),11,1+7*1)-WEEKDAY((DATE(YEAR(E1),11,8-1))))-1),MONTH((DATE(YEAR(E1),11,1+7*1)-WEEKDAY((DATE(YEAR(E1),11,8-1))))),DAY((DATE(YEAR(E1),11,1+7*1)-WEEKDAY((DATE(YEAR(E1),11,8-1)))))),E1<(DATE(YEAR(E1),3,1+14*1)-WEEKDAY((DATE(YEAR(E1),3,8-1))))))
It seems to kick in during the SECOND Sunday in November. I'm particularly flummoxed now. It's been an interesting intersection of "I'm pretty good with computers and layout design" and now all of a sudden diving deeper than I'd ever thought i'd go in excel. Keeping that in mind, I'm starting to feel a little out of my depth already and I'm sure VBA could do this easily but I wouldn't know the first thing about what I'm doing which means if anything ever goes wrong because someone accidentally deleted something I won't be able to fix it.
TL;DR: Trying to hit a moving target of a date based off of a dynamic entry in E1. Based off of E1 find the first sunday in november and the second sunday in March of the following year (or i suppose current year once we roll back around to january)
=OR(DATE(YEAR(E1),11,15-WEEKDAY(DATE(YEAR(E1),11,1),2))<=E1,DATE(YEAR(E1),3,15-WEEKDAY(DATE(YEAR(E1),3,1),2))>=E1)
alternatively you can replace E1 in the formula with TODAY(). This equation will evaluate to True or False

Excel Formula for calculating time in round numbers with hours text

I'm trying to figure out a way to create an excel spreadsheet that will allow me to keep track of how many hours I've earned per each paid holiday my company offers, then keep track of how many hours I've used and what's remaining. But I'm unsure how to calculate this properly.
I could easily do the math my self as it's a simple lay out, but I'm trying to find a way that will just let me enter the numbers for earned and used and walk away from anything else.
What I'm trying to do is the follow:
Have multiple sections. In the first section it'll be my holidays. So in like Column A, working down I'd have New Years, Memorial Day, July 4th, etc. Column B working down would be time earned. But this would be labeled in each cell as "8 Hrs" or "4 hrs". Column C would be time used in the same format "4 hrs" "8 hrs". Then Column D would simple be hours remaining.
Now in the second section I'd have holiday hours earned, which is 2 weeks. Not too sure how to lay it out, and then I still have my sick days, but not sure if I should include that in section 2 or not with the vacation time.
I'd like a way to be able to simply Calculate B2 - C2 = D2. So 8 Hrs - 4 Hrs = 4 Hrs (to show 4 Hrs remaining for each line item.)
Problem is I'm unsure how to calculate remaining time simply because of the Hrs suffix. And with that I also can't calculate total time still remaining, both for holiday hours earn and vacation/sick hours.
Yes, it's easier for me to track it as 8 Hrs rather than 1 day, etc.
Any advice on how to formulate this. Or if anyone knows of a premade template that fits this type of scenario, that I could then just take and integrate into my own spreadsheet.
Sorry if this is confusing in any way.
Also, As I'm no excel wizard, unsure if this is relevant or not, but I'm using Excel 2016, as part of the Office suite.
Another option is to just leave the number as it is and label the column accordingly. Do you really need to see "hrs" in every cell when you know you are tracking hours?
Use a custom number format of,
[>1]0 \H\r\s;[=1]0 \H\r_);0 \H\r\s;[Red]#
... and treat all hours as integers.

Resources