How To Ignore Blank Cells for a Formula - excel

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.

Related

Incrementing a Cell Reference By x

I am trying to average a large data set within Excel where there is data by 30 minute periods for each day of the month. I have a header for 'start date' and 'Start time' which displays 00:00:00 - 23:30:00 for each day, with the data in question in columns to the right. I am trying to develop a formula which averages data which concerns 00:00:00 - 11:30:00 for each day and 12:00:00 - 23:30:00 for each day (AM:PM).
I have one header for AM values and another for PM values, and Im looking to average both these elements for each day of the month
I have used the following formula which does work:
=AVERAGE(OFFSET(C6,24,0,-24))
This formula capture the range from 00:00:00 - 11:30:00 and averages it like I want, but when I drag the formula down to the next cell, C6 increments to C7, but I want it to increment by 48 each time, meaning C6 should become C54. This means when I drag it down each time it will average the AM values for 02/01/2019 and so on.
Is there any way the cell reference in the above formula can increment by 48 instead of 1 each time it is dragged down into another cell?
Sample Data
Expected output
I made up a dataset kind of like yours:
The formula I've used in F4 to obtain the average of values, when date is '01/01/2019' and time is AM, is AVERAGEIFS:
AVERAGEIFS function
My formula is:
=AVERAGEIFS($C$6:$C$101;$A$6:$A$101;E4;$B$6:$B$101;"<"&0,5)
You can use it and just drag down. As you can see in the image above, the formula returns 27,07
The formula will work only with AM because the criteria is "<"&0,5. In the column where you want to do the average of PM times, we would use the same, but changing criteria to ">="&0,5, this means:
=AVERAGEIFS($C$6:$C$101;$A$6:$A$101;E4;$B$6:$B$101;">="&0,5)
Hope you can adapt this to your needs.
NOTE: Because your data is in a Pivot Table (you never mentioned that), if the Pivot Table changes, you'll neeed to adapt the formula. A solution would be using ranges from row 6 until last one, so the formula will take always all the rows. Remember to not show total row or it may affect the result.
OPTION 2: In case you can add an extra column to original data (not in the Pivot Table), maybe this can help a lot.
I've used same data than before, but I added an extra column, named AM/PM with a formula on it:
=IF(B6<0,5;"AM";"PM")
It looks like this:
Then I created a Pivot Table based on it, with a configuration:
Field Start date to section of rows.
Field AM/PM to columns.
Field VALUE to values section, but instead of suming up, I did average operation.
I get this on my Pivot Table:
As you can see, AM for 01/01/2019 is 27,07 (the oher numbers are based on random numbers I made up).
Hope this can help.
If you absolutely must go with the AVERAGE(OFFSET()) solution I would have a 'helper' cell (in this case J6) with 1 in it, then J7 have =J6+48, then the main formula could be
=AVERAGE(OFFSET($C$6,J6,0,24))
Then when you copy the formula down, you'll also need to copy down from J7.
The Rows argument is purpose built for what you want to do. Going to efforts to change the reference cell defies this purpose.
Edited because I missed the AM/PM split:
I think, however, AVERAGEIFS() will fit your requirement better. This takes the average of all values in column C where the date in column A matches that in cell G6 (Change this to wherever your output is). This will avoid errors should any of your dates have any half hour periods missing.
=AVERAGEIFS($C:$C,$A:$A,G6,$B:$B,"<"&TIMEVALUE("12:00:00"))

Sumif using offset and columns functions

I want Excel to find a date and sum the preceding 12 cells in the row based on a keyed date.
I have 3 1/2 years of monthly financial data. I want to get the trailing twelve month totals based on a selected date. In my 'data input' tab row 111 is the month and row 112 are the respective revenues. H43 is my input cell for the date I want it to calculate from.
=SUMIF('data input'!$D$111:$AR$111,$H$43,OFFSET('data input'!$D$112,0,COLUMNS('data input'!$D$112:$AR$112),1,-12))/1000
If I key in 4/30/2019 I want the formula to return the total revenues for MAY 2018 - APR 2019. When I step through the formula, it always references the last 12 columns in the array regardless of what date I input and the value comes back to 0.
What your OFFSET function is doing is first going to the end (because the start column=the third argument is set to you by the COlUMNS() formula, which is constant and equal to the length), and then going back 12 months. This is why the referenced ones are the last 12.
The SUMIF is wrong in many ways. You are trying to map an array of all (about 50?) columns to an array of 12. The first and last parameter of SUMIF must be the same length. Not only that, but you have added H43 as the criterion, which even if you got the last parameter correct, would only return you the one month you selected, and not the rest 12.
What you really need to do is simply SUM the correct range found by OFFSET. Try this:
=SUM(OFFSET('data input'!$D$112,0,-12+MATCH($H$43,'data input'!$D$111:$AR$111,0),1,12))
(Having a negative size feels alien to me, so I moved the starting point back by 12)
You might have to play around with MATCH a bit, eg using a conversion function from H43 to the values present in the 111 row.
And of course, you might have to do some editing on the formula if your H43 belongs to the first 11 columns.

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.

Lookup date, return sum of previous 5 days

I am needing a bit of help on a formula which I have been amending for a while now with no success going through vlookups, indexmatches, sumproducts etc.
Basically, on one tab "weekly summary" I have the date contained in cell H2 which will only ever be set to a monday. I need a formula in cell B3 that will look up to a different tab "Raw Data Input" based on this date in cell H2, and return the sum of the values for the previous week (previous 5 amounts using the workdays formula on raw data input tab).
So for instance if this was today, 14th Nov, I would want the sum of the values from 7th-11th Nov.
Is this possible without doing 5 separate vlookups to different dates?
Ps. I will eventually form this into a macro, however as I have a number of tasks to complete before I get to that stage, I would prefer it as a formula, to get everything set up before I start adding VBA.
You can use SUMIFS where your multiple conditions are dates are less than 14th Nov, but greater than 14th Nov - 7
=SUMIFS(A:A,B:B, "<"&$H$2,B:B, ">"&$H$2-7)
Whereby A:A is the sum range, and B:B is the columns with dates.

MEDIANIF formula using months

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

Resources