How do I get the average number of occurrences of a date for each day of the week in excel? - excel

Let's say I have an excel spreadsheet recording some event that reoccurs often multiple times a day, sometimes not at all in a day. So I record the date and a bunch of other information for the event every time it happens. What I'm trying to find is, the average number of times this event occurs on each day of the week.
list of dates
So I want it to look at each day of the week, and find the average number of dates matching each day of the week, starting at the first date and ending at the last date. It should also take into account missing dates, so if there's a Friday with no records, that should affect the average occurrences for Friday.
I've tried using a Pivot Table to find this, and it can get me most of the way there, but it doesn't know to include missing dates within the "count of date" column.
pivot table
I'm not trying to find the average of some other value per day of the week, just the average occurrences of a date per the day of the week. Is this something that is possible in excel, or will I need to use scripts?
For an example where there's multiple weeks of data, I would expect to get a table of results like this:
Day of the week
Average
Mon
2.50
Tue
2.00
Wed
2.50
Thu
2.50
Fri
1.00
Sat
2.50
Sun
2.50
With Friday being lower as there is no Friday date in the provided range (the first Friday has 2 records, and the second Friday has 0 records).

We would need more data to really verify it (try it and let me know). You can use the following formula in cell D1:
=LET(A, A1:A14, B, B1:B14, wdays, TEXT(SEQUENCE(7), "ddd"),
cnts, COUNTIFS(B, wdays, A, TOROW(UNIQUE(A))),
ones, SEQUENCE(COLUMNS(cnts),,1,0), totals, MMULT(N(cnts>0), ones),
sum, MMULT(cnts, ones), HSTACK(wdays, IFERROR(sum/totals,"")))
Or you can use a more succinct formula via BYROW as follows:
=LET(A, A1:A14, B, B1:B14, wdays, TEXT(SEQUENCE(7), "ddd"),
cnts, COUNTIFS(B, wdays, A, TOROW(UNIQUE(A))),
HSTACK(wdays, BYROW(cnts, LAMBDA(x, IFERROR(AVERAGE(IF(x=0,"", x)),"")))))
Here is the output:
Note: If you want the result presented starting from Monday, then define wdays as follow: TEXT(SEQUENCE(7,,2),"ddd").
The name cnts, has the counts per week days (rows) and per columns (unique dates from column A). The rest is just to do the match to calculate the average. We ignore dates with no counts for calculating the average, as per my understanding of the sample input data from the question.

Related

Calculating Monthly (Offset) Average In Excel

I have daily data entries for 3 indices. They do not feature every day of the month and for some days entries for one of the indices will miss; the quantity of cells per month differ. I want to calculate the average value for these individual indices starting the 16th of the prior month and going to the 15th of the current month (or the first date after the 15th/last day before the 16th if there is no entry). For example, in the screen grab below, the average for MXWO in the month of February would be the average of the array B14:B36 (and for January, B2:B13).
What my data looks like
I want to produce 4 columns: Date (Month-Year), average of MXWO, average of JPMIGHYS, and average of USTWBGD. Each of these averages needs to use the methodology described above. How might I achieve this?
I've tried using the OFFSET function, but since the cell increment changes month to month (there is a different amount of missing cells per month), this didn't work.

How to count entries on monthly basis? Such that same row/entry can be counted in multiple months if conditions are met

I am trying to make a bar chart with X- axis showing timeline with respect to months (Jan, Feb, March etc). On Y-axis, I want to count how many [KRI] are there in each month based on their [Status Category]?
I have two conditions though:
1) If [Status Category] is 'Final', count that KRI in all months between [TRIGGERDATE] month and [statchedate]. for example, same KRI should be counted in Jan, and Feb and March etc (from time it was open till the time/month it was closed).
2) If [Status Category] is NOT Final, count that KRI in all months between [TRIGGERDATE] month and today's month.
In the picture below with the data sample, the pink colored blocks shows when the KRI should NOT be counted in that particular month.
I am trying to write a custom expression using if statement, but I am not able to figure out how would spotfire know that a KRI should be counted between [Triggerdate] and [Statchedate]? Or for instance, between [Triggerdate] and [today]
I am also thinking about adding a calculated column that will determine if the KRI should be counted in how many months? (but this will be ongoing data, so I am afraid that my column would keep on expanding..)
Any suggestions would be very much appreciated :)

how to do 2 seperate operations if start time of shift is before 7 but end time is after 7

I'm trying to make an excel sheet where I only need to put in start and end time and excel chooses the correct pay rate and how many hours I've worked (already done) and outputs how much I've earned. So far I have a column (D) for the date of shift (DAY, day of month, Month, year) column for hours worked (E), column for start time and end time (F, G) I have already written the formula to calculate the hours worked but in Australia where I live my pay rate increases after 7 PM, and increases again after 12 AM. Is there a way to have excel automatically know that it needs to take the hours worked before 7 PM and multiply it by a 24.41, then the hours worked between 7 PM and 12 AM by 26.54 etc, if my shift starts for example at 5:30 pm and ends at 3 AM?
These are the different payrates at the different times: (Time is in cell A1, Pay rate is B1, etc)
Time Pay Rate
Regular $24.41
Mon-Fri 7pm-midnight $26.54
Mon-Fri 7midnight-7am $27.60
Saturday $29.30
Sunday $34.18
Public Holidays $48.83
Thanks in advance
Solutions to all of these type of questions use the standard formula for overlapping time periods
=max(0,min(end1,end2)-max(start1,start2))
The best way to do it IMO is to simplify it two ways
(1) By splitting any times that cross through midnight into two parts, one up to midnight and one from midnight onwards
(2) Using a lookup table to match the conditions (day of week and time of day) to the payscale.
Then use an array formula to do the lookup and calculation. Because you can't use MAX and MIN as above in an array formula, you have to write it out using if statements and the formula gets pretty long
=SUM((WEEKDAY(E2,2)>=PayRates!$A$2:$A$10)*(WEEKDAY(E2,2)<=PayRates!$B$2:$B$10)*24*PayRates!$E$2:$E$10*
IF(IF(G2<PayRates!$D$2:$D$10,G2,PayRates!$D$2:$D$10)-IF(F2>PayRates!$C$2:$C$10,F2,PayRates!$C$2:$C$10)<0,0,
IF(G2<PayRates!$D$2:$D$10,G2,PayRates!$D$2:$D$10)-IF(F2>PayRates!$C$2:$C$10,F2,PayRates!$C$2:$C$10)))
This has to be entered using CtrlShiftEnter
This is how my pay rates are arranged
NB When the finishing time of a pay rate is midnight, it is entered as 1 (you want it to be 24:00, but entering 24:00 just gives you the same as 00:00)
And this is the main sheet
With the following columns
A,B and C are your input.
Split
=B2<A2
StartDate1 and StartTime1 are just a copy of your input
EndTime1
=IF(Split,1,B2)
StartDate2
=E2+Split
StartTime2
00:00
EndTime2
=IF(Split,B2,0)
Total1
The main formula
Total2
The main formula copied across by four columns to give any pay for the second day when the shift goes through midnight.
Total
Total1+Total2
Public holidays can be added fairly easily.

Calculate number of specific days in range

How can I count the (fractional) count of specific day of the week in a range? For instance, if the range is from Monday, June 3 12:00 P.M. to Tuesday June 4 12:00 P.M., and I want to count the number of Mondays, the formula would return the result 0.5.
I've already found a formula for the integer number of days:
=SUM(INT((WEEKDAY($B2-x)+$D2-$B2)/7))
where x is the day of the week of interest (1 to 7). Of course, it would need to be modified to return the aforementioned result. How would I do so?
You can get the total number of Mondays (including both start and end date) with this version (you don't need SUM)
=INT((WEEKDAY($B2-2)+INT($D2)-INT($B2))/7)
...and then do an adjustment to take into account the start/end days, e.g.
=INT((WEEKDAY($B2-2)+INT($D2)-INT($B2))/7)-IF(WEEKDAY($D2)=2,1-MOD($D2,1))-IF(WEEKDAY($B2)=2,MOD($B2,1))
I don't really recommend it (it's much more resource-hungry) but this version should give you the same result
=SUMPRODUCT((TEXT(B2+(ROW(INDIRECT("1:"&ROUND((D2-B2)*1440,0)))-0.5)/1440,"ddd")="mon")+0)/1440
It tests every minute within the date range to ascertain whether or not it falls on a Monday (assumes that you don't go down to seconds)

Elapsed Days Hours Minutes Excluding Weekends and Holidays Time

This sounds simple but I have been pulling my hair out trying to figure out a solution. Any help before I go bald would be great.
I need a formula which is able to
calculate the duration in (days, hrs, mins) between two date\time values (eg 05/12/2012 5:30 PM and say 07/12/2012 5:45 PM);
excluding weekends and holidays.
I would like the result of the formula to read as follows "e.g 2 Days 0 Hrs and 15 Mins".
Thanks
Link to sample workbook
You can use NETWORKDAYS and NETWORKDAYS.INTL to achieve this
A bit of manipulation is required as these return net whole days:
Use these functions to calculate the number of non workdays, then subtract from the difference between start and end dates
=E3-D3-(NETWORKDAYS.INTL(D3,E3,"0000000")-NETWORKDAYS(D3,E3,$A$16:$A$24))
This returns the working day difference, where 1.0 = 1 day
NETWORKDAYS.INTL(D3,E3,"0000000") calculates whole days between the two dates (no weekends, no holidays)
NETWORKDAYS(D3,E3,"0000000",$A$16:$A$24) calculates whole working days days between the two dates (Sat/Sun weekends, holidays as per your list in $A$16:$A$24)
Difference in non-working days between the two dates.
E3-D3 is time between start and end date/times (1.0 = 1 day)
Use custom number formatting to display thye result in the format you require
d "Days" h "Hours" mm "Mins"
Note: this format won't work for negative values, you will need an alternative for when end date is before start date.
The following formula works like a treat with no additional formatting or manipulation.
To make it more stable I have turned all the holiday dates for UK 2012/13 into ‘Excel Serial Number’ format and placed them in an array bracket.
Replacing the "D5" in the formula with your cell reference for your course or metric "End Date" and "E5" with your course or Metric for "Completion Date".
=IF(E5<D5,"-"&TEXT(D5-E5,"h:mm"),NETWORKDAYS(D5,E5,({40910,41005,41008,41036,41064,41065,41148,41268,41269,41275,41362,41365,41400,41421,41512,41633,41634}))-1-(MOD(E5,1)<MOD(D5,1))&" days "&TEXT(E5-D5,"h:mm"))

Resources