How to display the past 17 trading days (business days) when looking up Stock History in excel - excel

I'm using the new STOCKHISTORY function in Excel and I'd like to always display the past 17 trading days from the point I indicate. The problem is with long weekends and holidays this alters the amount of business between two dates. I'm not sure if this will be a difficult question because I think the solution is not dependent on the fact that I'm using the STOCKHISTORY function. I have attached a photo with a simple explanation. On the left the formula for STOCKHISTORY is =STOCKHISTORY(E2,C4-C6,C4,0,1,0,2). This displays 17 business days because 22 is the magic number. On the right though if I query July 22nd with 22 day difference I only get 16 days. This is further wrong on many other dates.
I am open to having a separate reference on another sheet that has dates/formulas. I tried this but couldn't figure out a formula to pull down. Photo B displays an example of the correct number of dates that would show 17 trading days. I am also open to displaying more than 17 trading days as in the future I will need to alter the amount of trading days needed (I might need to display 15 days or 20 days).
In my head I feel like the answer has something to do with the NETWORKDAYS function and/or I should make a list of all the trading days in a year and then make a formula taking the current day and taking away a specific day. Or I could be totally wrong and the answer is obvious.

So I figured out an answer after reading some documentation. There is most likely better answers but it solves the problem enough.
So I created a list of all trading days (business days) as you can see in column O. Then in Column L a list of nearby holidays (Only needed a few exceptions). Then using the formula =(O35)-(WORKDAY(O36,-17,$L$35:$L$36)) I get the right solution which I verified in my example photo posted earlier. You could theoretically get a different number when doing your own calculations (i.e the answer 24 and 23 are both correct).

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

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.

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

Need to calculate last 5 value average from today's date using only work days (weekdays Mon, Tue, Wed, Thu, Fri) using excel

Trying to show a rolling average of pieces produced from the last 5 work days.
Currently I am tracking all days Mon-Sun and taking the last 5 days.
Here is my current formula:
=SUMIFS(AL:AL,AK:AK,">="&TODAY()-5,AL:AL,"<="&TODAY())/5
With AL:AL being the date column and AK:AK being the pieces produced.
I Can't figure how to arrange the data and dates to get my last 5 days average.
This is not difficult with a helper column. As you indicated in the question, the arrangement is important. First, organize your data with the most recent values at the top. So AL1 will always hold today's date.
In AM1 enter:
=IF(OR(WEEKDAY(AL1)=1,WEEKDAY(AL1)=7),"",1)
In AM2 enter:
=IF(OR(WEEKDAY(AL2)=1,WEEKDAY(AL2)=7),"",IF(SUM(AM$1:AM1)=5,"",1))
(column AM defines the values to be averages)
Then in another cell enter:
=SUMPRODUCT(--(AM1:AM10=1)*(AK1:AK10))/5
Some beginners place the most recent data at the bottom of a column. This usually make it more difficult to analyze.
I think your SUMIFS() function is incorrectly reproduced. The first argument is the "sum_range," the data to be summed, so that should be the number of pieces.
Also, you are getting 6 days including today. If you want 5 days (and if you have data for today), then you have to subtract 4 instead of 5.
You can accomplish what you want with this formula, I think:
=SUMIFS(AK:AK,AL:AL,">="&WORKDAY(TODAY(),-4),AK:AK,"<="&TODAY())/5
If you don't actually have data for today, then subtract 5 instead of 4.
This also depends entirely on your not having any data for weekend days. If you have production data for weekend days, then the averages will be off (they will include extra days).
If you have data for both weekdays and weekend days, you will have to use something like #garysstudent suggested.

Excel - Evaluate multiple cells in a row and create report or display showing lowest to highest

In an Excel 2003 spreadsheet, I have the top row of cells calculating the number of days and hours I have worked on something based on data I put in the cells below for each category. For example I enter the time spent on Programming, Spoken languages, house, piano, guitar...etc. The top cell in each category will keep track of and display how many days and hours I spent as I add the time spent for each category each day. I want to evaluate this top row and then list in a "report" (like a pop up box or another tab or something) in order from least amount of time to the most amount of time. This is so I can see at a glance which category is falling behind and what I need to work on. Can this be done in Excel? VBA? Or do I have to write a program from scratch in C# or Java? Thanks!
VH
Unbelievable... I've been scolded for trying to understand an answer and requested to mark this question answered. I don't see anything to do this and could not find anything that tells you how, so I'm just writing it here. MY QUESTION WAS ANSWERED... But thanks anyway...
Consider the following screenshot:
The chart data is built with formulas in columns H3:I3 and below. The formulas are
H3 =INDEX($B$3:$F$3,MATCH(SMALL($B$2:$F$2,ROW(A1)),$B$2:$F$2,0))
I3 =INDEX($B$2:$F$2,MATCH(SMALL($B$2:$F$2,ROW(A1)),$B$2:$F$2,0))
Copy down and build a horizontal bar chart from the data. If you want to change the order of the source data, use LARGE() instead of SMALL().
Alternative Approach
Instead of recording your data in a matrix, consider recording in a flat table with columns for date, category and time spent. That data can then easily be evaluated in many possible ways without using any formulas at all. The screenshot below shows a pivot table and chart where the data is sorted by time spent.
Edit after inspecting file:
Swap rows 2 and 3. Then you can choose one of the approaches outlined above.
Consider entering the study time as time values. It is not immediately clear if your entry 2.23 means 2 hrs and 23 minutes, or 2 hrs plus 0.23 of an hour, which totals to 2hrs, 13 minutes.
If you are using the first method, then all your sums involving decimals are off. For example, the total for column B is 7.73 as you sum it. Is that meant to be 7 hrs and 73 minutes? That would really be 8 hrs and 13 minutes, no? Or is it meant to be 7 hrs and 43 minutes? You can see how this is confusing. Use the colon to separate hrs and minutes and - hey - you can see human readable time values and don't have to convert minute values into decimals.

Resources