MEDIANIF formula using months - excel

I've written the following "MEDIANIF" array formula to give me the median of values (percentage returns) from column B that correspond to months in column A. In other words, I want the median of all values that correspond to January, February, March, etc...
This formula works perfectly for all months, except for January. I've manually verified it is working fine for all other months, but for whatever reason, it just returns 0 for January. This isn't a formatting issue or anything like that (everything is formatted consistently). I cannot for the life of me figure out why it won't work for January.
=MEDIAN(IF(MONTH(Data!$A$4:$A$65536)=1,Data!$B$4:$B$65536))
I'd post an image, but this is my first post and I can't post pics until i have at least 10 reputation!
The data is arranged with calendar months in column A (last trading day of the month) and percentage returns (formatted as a percent) in column B.
Any help is very much appreciated!
Thank you!

Excel will treat blank cells as zero (in this sort of formula, at least) and zero will be deemed to be a date in January (January 1900) so any blank rows will contribute a zero to the January median calculation; that's why you get incorrect results - add another check to ensure that the cells aren't blank, i.e.
=MEDIAN(IF(Data!$A$4:$A$65536<>"",IF(MONTH(Data!$A$4:$A$65536)=1,Data!$B$4:$B$65536)))
Alternatively you could limit the formula to rows with data - perhaps employing dynamic named ranges if the amount of data is variable

Related

Excel - Get hourly averages for data spanning 1 year (8760 data points)

I have an excel document with values for every hour for every day of a year.
In total there are 365*24=8760 values.
I would like to get the average value at every hour, (etc at 00:00, 01:00, 02:00..)
I was thinking maybe to sum every 24th value and then divide it by 365 but I don't know how to sum every 24th value.
Does anyone know how to do that?
Thanks for any help!
The clearer way of doing it is using a column to get the hour of each data point and adding a AVERAGEIF formula to calculate the average of every hour.
I am assuming your date/time is on A2:A8761 and the values on B2:B8761.
On C2, add the formula =HOUR(A2) and drag it down to find the hour of every data observation (for newer excel versions you can also
do =HOUR(A2:A8761) and the formula will automatically spill down). The results are numbers from 0 to 23.
Building the summary table:
Add a column listing the numbers 0 to 23 to represent the 24 hours. I did it on column E2:E25. Note that those are numbers, not date/time.
On F2, add the formula =AVERAGEIF($C$2:$C$8761,E2,$B$2:$B$8761) to calculate the average of the hours listed on column E. Then, drag it down. Finally, you will have the values you need on F2:F25.
Find bellow my result.
Please let me know if you have any question so I can improve the answer.

Calculating total monthly precipitation values using SUMIF function to specify date window

I've got an excel sheet with dates in one column (daily) and total precipitation values for that date in another column from 01/01/2000 to 31/12/2021.
I want to calculate the total monthly precipitation values from 2000 to 2021.
The formula I have been using after some research online was (which I was planning on iterating over the months):
=SUMIFS(B2:B8036,C2:C8036,"<="&DATE(2003,9,1),C2:C8036,">="&DATE(2003,9,30))
The values I want to sum (precipitation) are in the B column, the dates are in the C column. However, I get a zero value returned in the cell when I run the formula, even though the actual value should be 131.94.
I'm not sure what mistake I made in my formula.
My operators were wrong, changing it to
=SUMIFS(B2:B8036,C2:C8036,">="&DATE(2003,9,1),C2:C8036,"<="&DATE(2003,9,30))
solved my problem.

N-Count Days For Changing Dates For Ecommerce Shipment Sheet

I have to submit a daily MIS for orders which are Undelivered For less then 2 Days, Undelivered Between 3-5 Days and 5+ Days.
Currently i'm doing this manually by counting from the Purchase Date forward. So e.g. for an order of 11th March, i'll just count 2 days till 13th (If undelivered) and type 1 in front of the column and do a count manually of all orders outstanding in each column.
The problem arises as the column descends and the dates get further and further away from current day.
This is tiresome but i can't seem to find an algorithm that can do this automatically.
Can anyone help please.
Consider this screenshot:
Cell A1 has the date you want to compare to. Don't user the Today() function, since it is volatile and can slow down the workbook. Just manually put in the desired date.
The formula in cell E2 is
=IF(D2="undelivered",IF($A$1-C2<=2,"less than 2",IF($A$1-C2<=5,"3 - 5 days","5+ days")),"")
In words: if the status is "undelivered", calculate the difference between purchase date and A1. If it is less than 2, return that text, if it is less than 5, return that text, otherwise return the third text.
Copy that formula down.
In cells G3 to G5 you see each of the three texts and next to it is a formula. Starting in H3
=COUNTIF(E:E,G3)
copied down to H5.
Your layout may differ, so you will need to adjust the formulas accordingly.

How to make criteria in AVERAGEIFS update automatically?

I am trying to make my AVERAGEIFS criteria update automatically according to the day of the year (in this case only for 2014). My original AVERAGEIFS formula works perfect =AVERAGEIFS($B$2:$B$35041,$A$2:$A$35041,">=1/1/2014",$A$2:$A$35041,"<1/2/2014"), but I have to manually edit it for each day of the year.
I have tried modifying formulas I have seen in other posts here, but no luck so far. I want to average the values in column B (Amount) for each day in column A (Date). I have 96 time slots for each day of the year, hence the 96 entries in column A with the same date, e.g. 1/1/2014 and so on until 12/31/2014. How can I modify the formula so that it automatically adjusts the day when I drag it down?
Here is a screenshot of the data:
Screenshot of data
Any help is much appreciated!
EDIT: Updated formula below; I had misread the original question as to how your data was formatted. You can put this formula in B2 and copy down.
=AVERAGEIFS($B$2:$B$35041,$A$2:$A$35041,">="&$A2,$A$2:$A$35041,"<"&($A2+1))
Your original comparison operator hardcoded a date as a string. We can simply concatenate the value of a cell into that comparison string instead.
Granted, this will do the same calculation for each of the 96 entries for each of the days in your sheet. You could add a second sheet for the averages with just the distinct days of the year listed in A and an average calculation in B.
EDIT 2:
If your entries in column A have fractional date information (i.e. with hours, minutes, and seconds), converting the dates to integers will drop any fractional component:
=AVERAGEIFS($B$2:$B$35041,$A$2:$A$35041,">="&INT($A2),$A$2:$A$35041,"<"&INT($A2)+1)

How To Ignore Blank Cells for a Formula

I'm tracking hours for my company and I need to see the updated hours daily. I have everything formatted how I want it, except I want two columns to show how many hours over and under each employees current hours are.
What I have right now is
=(D3-C3)+(F3-E3)+(H3-G3)+(J3-I3)+(L3-K3)+(N3-M3)+(P3-O3)
But it is including all the empty cells (for days that haven't been worked yet) as a zero.
I want a formula that can allow me to ignore those blank cells until they have content.
I can't just use a SUMIF >0 function because I need to count the number of hours employees have MISSED (i.e. scheduled 12 hrs, actually worked 0).
Here's an alternate approach to #Tom's, though it works on similar principles. This one, however, relies on your ability to add a couple of 'HELPER' rows, above your current data.
I'm assuming that row 1 will alternate between saying "PROJECTED", and "ACTUAL".
I'm assuming that row 2 will be dates for that week, in Date format. So A2 will be Jan 1 2015, B2 will be Feb 1 2015, C3 will be Feb 1 2015, or however often the time blocks go up. The key here is that the PROJECTED columns and the ACTUAL columns will each need the date in them.
The formula to check the variance between that row's PROJECTED amount and that row's ACTUAL amount, only for dates prior to today, is (for row 3 and copied down, and assuming the data goes to column Z):
=SUMIFS(A3:Z3,$A$1:$Z$1,"PROJECTED",$A$2:$Z$2,"<"&TODAY())-SUMIFS(A3:Z3,$A$1:$Z$1,"ACTUAL",$A$2:$Z$2,"<"&TODAY())
This checks to see the value of PROJECTED columns for that row, where the date is less than today, and subtracts the value of ACTUAL columns for that row, where the date is less than today.
If you are looking to compare with something other than TODAY(), you can set up a cell to be your 'comparison point'. Manual type the breakoff period you are concerned with into that cell, and replace "&TODAY()" with, say, "&AA1" [assuming your breakoff point is entered in cell AA1].
As it stands, either a very long series of IF's and OR's or an array formula:-
=SUM(IF(OR(D3="",C3=""),0,D3-C3),IF(OR(F3="",E3=""),0,F3-E3),IF(OR(H3="",G3=""),0,H3-G3),IF(OR(J3="",I3=""),0,J3-I3),IF(OR(L3="",K3=""),0,L3-K3),IF(OR(N3="",M3=""),0,N3-M3),IF(OR(P3="",O3=""),0,P3-O3))
=SUM(D3:P3*ISEVEN(COLUMN(D3:P3))*(C3:O3<>""))-SUM(C3:O3*ISODD(COLUMN((C3:O3))*(D3:P3<>"")))
The second one must be entered with CtrlShiftEnter
Note that it could easily be broken by insertion/deletion of columns.

Resources