Need to calculate last 5 value average from today's date using only work days (weekdays Mon, Tue, Wed, Thu, Fri) using excel - 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.

Related

Get sum of cells containing "Vacation" except when related date matches certain day & month

oversimplified i have two columns: Date and Text; I want to check my current amount of vacation days based on the first date in row 2, so i came up with the following formula:
="Available vacation days: "&YEARFRAC(A2;TODAY())*12*(25/12)
I calculate the fraction of the year based on the first date and todays date, multiply it by 12 to get months and multiply it again by the total amount of vacation days in my contract per month. Now i got another formula to collect me all cells in column B containing "Vacation", pretty straight forward:
=COUNTIF(B:B;"Vacation")
Now the interesting part - i got the formula who gives me a boolean if a datetime matches the 24th or 31st of december:
=AND(OR(DAY(A53)=24;DAY(A53)=31);MONTH(A53)=12)
I want to count vacation days happening on a 24th or 31st of december as a half-vacation day (0.5), and otherwise fully (as a 1). Then i want to combine my first statement with this result and subtract the used vacation days. I read about VLOOKUP and XLOOKUP but am unsure if this fits this purpose. I want to avoid having an extra column with my boolean returns and rather have this one cell giving me all the information combined.
Without introducing another column, and using DAY and MONTH
It's nearly impossible, and just unnecessarily so...
Please reconsider this, what will happen if you want to add 4th of July as a holiday?
Your formula =AND(OR(DAY(A53)=24;DAY(A53)=31);MONTH(A53)=12) only works for 1 row at a time. So, we can't ever use it with a list, because you will get the whole list as a result every single time. You can't divide them into smaller lists and join them together, there is no such functionality without VBA.
In the future, do not set arbitrary constraints like "no additional columns", you can hide them if you don't like them. And if you don't need them, remove unnecessary rows like non-vacation rows. They are irrelevant, so why not separate the two.
Just to prove my point, here's the solution you wanted:
Solution
=COUNTIFS(B2:B9;"Vacation") - (COUNT(IFERROR(FILTER(FILTER(FILTER(A2:A9;B2:B9="Vacation");MONTH(FILTER(A2:A9;B2:B9="Vacation"))=12);DAY(FILTER(FILTER(A2:A9;B2:B9="Vacation");MONTH(FILTER(A2:A9;B2:B9="Vacation"))=12))=31);0))+(COUNT(IFERROR(FILTER(FILTER(FILTER(A2:A9;B2:B9="Vacation");MONTH(FILTER(A2:A9;B2:B9="Vacation"))=12);DAY(FILTER(FILTER(A2:A9;B2:B9="Vacation");MONTH(FILTER(A2:A9;B2:B9="Vacation"))=12))=24);0))))*0,5
It works, but it's a pain to read, use and maintain.
A2:A9 refers to the dates column
B2:B9 refers to the text column
So in the future, the last thing you want to do is set arbitrary constraints. Furthermore, why use functions like MONTH and DAY when we can just read the text? That way you could even create a table of holidays to search for instead. That will be no fun task with this setup. (Oh, and if it's because of the year, just strip it away from the text when you want to know only the month and day.
Best of luck!

How to display the past 17 trading days (business days) when looking up Stock History in 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).

Time series mock data generation for 16 years of quarterly data in Excel or Matlab

I would like to generate a mock time series quarterly dataset from, say, 2000-2016 for a variable (quarterly credit growth) that averages around a certain value (say, 30%). Can anyone give a suggestion on how to do this in principle?
Edit: what I was implying were the actual data values for each time period, i.e. data with a certain mean and variance.
Found a solution with a code in Matlab, for anyone interested, see below in answers.
Excel approach:
You can make column A your date list. In A1, or A2 or more if you have header rows, you will have to seed your list by providing the first start date. Lets assume you put your seed date in A2. I would then go about adding 3 month to you start date using a formula, and copy down until you have hit your desired date. In order to add the 3 months I would use the following in A3.
=date(year(A2),Month(A2)+3,day(A1)
that will give you the first day of the month every 3 months. If you want the first day of the month every 3 months, set the day to 1 like so:
=date(year(A2),Month(A2)+3,day(A1)
And end of month could be calculated as:
=eomonth(date(year(A2),Month(A2)+3,day(A1)),0)
however I would prefer to do the end of month calculation based on the row you are in so I would do it more like:
=EOMONTH($A$2,(rows($A$2:A3)-1)*3)

Excel Trend Projection

I'm trying to find a trend projection that compares between same week of 2 consecutive years and also from previous weeks of a particular year. What is the excel formula that helps me to do this?
I need to find the projected values for week 15 all the way to week 53 for This year, based on
The previous weeks of This year (Week 1- Week 14) as well as
The same week Last year (Week 15)
You could use the Trend function, setting Known X's to Last Year weeks 1 to 14 and Known Y's to This Year weeks 1 to 14.
Then set the New X's to the same week for last year and the function will use the Least Squares method to extrapolate for this year.
If you use absolute references (e.g. $A$1:$A$10) for the Known X's and Y's, and a relative reference for the New X's, then you can just copy/paste the formula from This Year week 15 down.
Keep in mind though that the further you get from the Known values, the less accurate the forecast becomes...
Are you familiar with the add-in solver or Data Analysis? Sometimes you have to unhide it by going to options>add-in>"Data Analysis" to use it but it does simple analyses. You will find several helpful tools for doing stats in "Data Analysis."

Hours to working days

Where I work I don't get paid overtime, but I accrue holiday days for the overtime I work. I have the following spreadsheet which calculates how much overtime I've done and totals it in D15.
Now I want to calculate how many days this is, based on 8 hours per day. In D16, I've done =D15/8 and formatted it as h.mm \d\a\y\s, but this shows as 2.26 days instead of 2.4375 days.
What is the correct formula to use in D16?
Note to reader: this question led to multiple solutions some of which were discussed in the comments. Here is a summary of the solution found.
First solution
=(HOUR(D15)+MINUTE(D15)/60)/8
Explanation
Dates and time in Excel are stored as serial numbers, so 19:30 is actually 0.8125.
So, if you divide it by 8, you will get 0.1015625.
This latter value is worth 2.26 days
OP's version (thanks to Danny Becket (OP)) - see the comments below.
This solution now handles hours > 24.
=((DAY(D20)*24)+HOUR(D20)+(MINUTE(D20)/60))/8
or better (credits to Barry Houdini):
=((INT(D20)*24)+HOUR(D20)+(MINUTE(D20)/60))/8
The former formula has a limitation for large values, perhaps not relevant here but if D20 is 800:00 then you get the wrong answer (7 days rather than 100 days). This is probably because DAY function is giving you calendar day which will "reset" at 31, best to use INT in place of DAY.
Another easily understandable version
Divide by the length of the day as a time value:
=D15/"8:00"
More easily changed if length of workday changes
Enter:
in B3 8:3
in C3 16:3
in D3 =IF(B3<C3,C3-B3-1/3,2/3-B3+C3)
Select B3:D3, format as hh:mm and copy down as far as required.
Sum ColumnD and append *3 to the formula, but format as Number.
Add data by overwriting cells in ColumnB and/or ColumnC as required (defaults do not add to total).
Copes with overtime up to next regular start time (ie including past midnight, new serial number). 1/3 because standard working day is 8 hours (24 hours is unity for date serial counter). B3 and C3 could be hard coded but (i) there is no need and (ii) allows more flexibility. If to readily identify non standard start/finish could use conditional formatting.
Does not address weekend overtime but could easily be adapted to do so (eg add column, flag weekend day with 8 in that extra column then add that 8 [1/3] to the finish time).
Make sure that D15 has a number format of [h]:mm
then have D16 as =sum(D15/"8:00") should work fine
thats what i have tracking my annual leave, I work 37h pw with a leave day being classed as 7h24m or a half day of leave as "3:42"
I have leave taken as a cumulative figure assigned as [h]:mm in cell K2 of my spreadsheet
then I have K3=SUM(K2/"7:24") for days taken formatted as a general number
you may also need to change the date datum in excel to the 1904 date system http://support.microsoft.com/kb/182247/en-gb
to get this to work (only a problem if you have negative time as I do when calculating flex hours)

Resources