Rolling Average Excel - excel

I am trying to find an average function that is able to automatically update when data is added in the row.
For Example: If I have to phases of data 1 & 2. 1, has less data the 2 how do I find the average function no matter the amount of data.
I have done so much research and I can not find anything

=AVERAGE(1:1) - this will give the average of all populated numeric cells in row 1. Adjust the numbers as necessary for different rows.

I'm not sure if I understand your question: you mention rolling average and in top of that you say that you want it to be filled in when a new value is added. All those things are quite obvious in Excel. There's just a part which might be confusing, and that's the part where the averages should not be calculated when no values are filled in, so I come up with the following formula (first to be filled in in B6):
=IF(NOT(ISBLANK(A6)),AVERAGE(A2:A6),"")
The rolling average is the AVERAGE(A2:A6): it calculates the average of five subsequent cells in column "A". When you drag this down, you see that it changes into:
=IF(NOT(ISBLANK(A7)),AVERAGE(A3:A7),"")
, which is again calculating the average of the last five values in column "A".
However, there's an issue: when you drag this down over the whole "B" column, you'll get wrong values for the cases where the value in column "A" is not filled in, hence the IF(NOT(ISBLANK trick: it blocks the filling of the "B" column if there's no value in "A", and you end up with something like:
Is this what you are looking for?

Related

Excel "SMALL" "IF" another row is not blank

I try not to ask for help like this but this one is screwing my noodle.
I have a costing spread sheet that I have managed to manipulate to give me a monthly cost role up (if exists) VS part number. Part numbers column c, months row 3.
On another sheet I'm trying to list the part numbers next to the cost role up and relevant date (each part number may have multiple entries)
I just need to do a "SMALL" for the "date" row (Row 3) on my costing sheet "IF" the "correct part number row" (or a fresh MATCH/VLOOKUP for the part number) has data in it. Or some how have the small return the Column INDEX number. I could then use INDEX to return the correct date and value using SMALL and Column B (the number of costs per part number, so if there are 3 instances that column currently list 1,2,3 before starting the next part number)
So close..... but this last bit is a struggle. Its a shame SMALL cant return INDEX Column numbers.
Does anyone know how to get a "SMALL" to lookup a row (based on a column search criteria) and check if the column has data, if so include the that column header in the "SMALL"
Update...
Thanks for your comments. I've stripped out the problem into a separate sheet to make it a little clearer. (I'll upload if possible).
I've also completed the rest of the excel to show the whole process. In doing so I've discovered Headers are automatically converted to text and so added a column to work around this using "DATEVALUE".
The goal is to list the number of costs related to a part number so.... if 500111 has had a cost role up in 3 different months it will list them in the cost report. So.... part number, relevant column "date" from "Cost data" sheet and relevant cost (#that part number # that date). if I can get a list of dates from "Cost Data" columns and put them in Column D "Costing date (text)" next to the relevant part number i should be sorted. I've highlighted the column in red on the new screen shots.
Cost Report
Cost Data
lines highlighted in yellow just to show they are empty
Edit:
Almost there for anyone else trying this
=INDEX($B$5:$J$5,,SMALL(IF($B$6:$J$6>0,COLUMN($B$6:$J$6)),3))
I just need to figure out how to define a variable "ROW" within a SMALL(IF statement. I should then be able to reference the correct table row number (which I already have).
Anyone know how to put a variable ROW or COLUMN reference in a SMALL formula?
Did not understand the problem fully.
But like this you can have a variable Row in the small formula:
=SMALL($A$4:$A$10;ROWS($C$4:C4))

Multiple Responses in Excel's Reverse Lookup

I'm trying to make a schedule of available workers after they have given me their availability. I would like a list generated of all people who say they can work on a specific day.
Ideally I would create some kind of list that looks like this:
I'm actually trying to schedule volunteers for my swim team, not employees, but the idea is the same. The form that they are filling out can also have blank spots (not shown in data table above, but possible) and the dates in the first column will also be out of order. I can manually fix both of those things, but if there is a solution that does not require me to fill in the blanks or sort the dates that would be ideal. I'm using Excel 2019 on a Win10 PC.
Starting in I2 you would have
=IFERROR(INDEX($B$1:$G$1,AGGREGATE(15,6,COLUMN($B$2:$G$7)
/(INDEX($B$2:$G$7,MATCH(I$1,$A$2:$A$7,0),0)="yes"),ROWS($1:1))-COLUMN($A:$A)),"")
so you are finding the right row in B2:G7 by doing a match on the date in column A, then finding the first, second, third... column which has a Yes in it, and finally getting the matching name from the first row.
You can see what's happening by stepping through the formula with evaluate formula:
(1) find the right row in B2:G7 by index/match
It's matching the date (stored as a number, 43466) against the list of dates in column A. The matching position is 1, which gives the row, and the column parameter in the Index function is 0 so you get the whole row.
(2) Find which cells contain 'yes'
The values in the array which do contain yes will be replaced with true and the ones which don't will be set to false.
(3) Do the division
This is the crux of the whole thing. What aggregate is going to do is to ignore the #div/0 entries (because we used option 6) and work out the lowest (minimum) column which corresponds to a 'yes', which is 2. It's the lowest because rows($1:1) just works out to 1 so you get the 'first smallest'.
(4) Adjust the column so that you get it relative to the first column of B2:G7. You could just subtract 1, but I'm trying to make it so that it still works if you insert a column to the left of the range.
5) Then all that's left is to index into the list of names in B1:G1
ending up with Albert.
As the formula is pulled down, rows ($1:1) changes to rows ($1:2) etc. so you get the second smallest column with a yes in it and so you get the second name. Eventually it errors out when there are no more matching names so IFERROR comes into play and you get a blank cell.

Excel - Find all identical cells, sum separate cell in row for matches, output in other sheet

So, I've searched for an answer to this, but I can't find anything. Hopefully some Excel guru out there has an easy answer.
CONTEXT
I have a sheet that has two columns; a list of airport codes (Col A) and a list of fuel gallons (Col B). Column A has a bunch of duplicate entries, column B is always different. It's basically a giant list of fill-up events for aircraft over time at different airports. The airports can be the same, because it's one row per fill-up event.
PROBLEM
What I want to do is have a formula that takes the enter data set, finds all identical entries in Col A, sums the Col B values for the matches, and spits out the result on a separate sheet with one entry for every set/match.
OTHER STUFF
I do not have a reference list for Column A and I would rather not create one since there are thousands of entries. I would like to just write a formula that does all this at once, using the data itself as the reference.
All the answers I find are "create a reference list on a separate sheet", and it's driving me crazy!
Thanks in advance for any help!
-rt
Sounds that you need a formula version of remove duplicated for column A, and a simple sumif for column B.
Column A
=IFERROR(INDEX(Data!A$1:A$1000,SMALL(IF(
MATCH(Data!A$1:A$1000,Data!A$1:A$1000,0)=ROW(Data!A$1:A$1000),ROW(Data!A$1:A$1000)),ROW())),"")
Array Formula so please press Ctrl + Shift + Enter to complete it. After that you might see a {} outside the formula.
Column B
=SUMIF(Data!A$1:A$1000,A2,Data!B$1:B$1000)
Just change the range for your data.
Reminders: The formula in columnA should starts from Row#1, or you have to add some offset constant for adjustments.
Since the returning value of MATCH() represents the position of the key in the given array. If we wanted it to be equal to its row number, we have to add some constant if the array is not started from ROW#1. So the adjustment of data in Range(B3:B1000) is below.
=IFERROR(INDEX('Event Data'!B$3:B$1000,SMALL(IF(
MATCH('Event Data'!B$3:B$1000,
'Event Data'!B$3:B$1000,0)+2=ROW('Event Data'!B$3:B$1000),
ROW('Event Data'!B$3:B$1000)),ROW())-2),"")
Further more, the range should exactly the same as the data range. If you need it larger than the data range for future expandability, an IFERROR() should added into the formula.
=IFERROR(INDEX('Event Data'!B$3:B$1000,SMALL(IFERROR(IF(MATCH(
'Event Data'!B$3:B$1000,'Event Data'!B$3:B$1000,0)+2
=ROW('Event Data'!B$3:B$1000),
ROW('Event Data'!B$3:B$1000)),FALSE),ROW())-2),"")
Lastly, I truly recommended that you should use the Remove Duplicated built in excel since the array formula is about O(n^2) of time complexity and memory usage also. And every time you entered any data in even other cells, it will automatically re-calculate all formulas once the calculation option in your excel is automatic. This will pull down the performance.

Comparing dates in two columns with matching criteria

I'm trying to fill out a sheet with a somewhat complicated criteria, I have four columns I'm interested in, however the columns are mixed into a much larger table, sorry vlookup :(
There are two columns that contain an ID# and a Category, one column with date and time stamp, and one that MAY contain a date and time stamp. (Column1,2,3,4 respectively)
Column 3 is when an action took place, Column 4 is the next time that action with the same ID# and Category has to have been completed by.
Essentially I need a cell(s) that will check for a date in Column 4, if there is one, find the next value in Column 3 that is greater than that of column 3 in the row with the value in Column 4, AND has the same ID, AND Category and compare them to see if it was done on time, preferably also by how much if it was late.
I'm able to find it almost with:
{=MAX(IF([#[Column 2]]=[Column 2],[Column 4]))}
Entered as an array formula, however that will only give me the last time that Category was given a "Next Due Date" and similarly with Column 1 replaced for Column 2 in the code sample above, I only get the last time that ID# was given a "Next Due Date".
As some Event ID# can be around for many days, and can run concurrently with others there's no guarantee all IDs will be grouped, nor Categories within those IDs.
It appears any attempts to add an AND(.. function break the array, though I'm not positive I'm not just messing up the placement of it.
It's perfectly fine if the solution involves creating helper cells.
The table is sorted chronologically by column 3 with the latest date at the top if that's any help.
TYVM for even taking the time to read this :)
Edit 1:
Sample Data
I've included an image with some sample data, to clarify the awkward sentence above. The orange arrows are pointing to two dates that would be compared and the event was late. the Green points to a group that was on time.
the categories are
Those two are being compared because each set has the same category, and ID. I hope that clears it up :)
You could try this formula (goes into column E):
=IFERROR( IF($D2<>"", LOOKUP(2,1/($F1:$F$2=$F2),$C1:$C$2), ""), "")
Very important here are the $ signs, as the searched area is supposed to move with the row. (Note: this formula goes into E2. You then copy > pastespecial (only Formulas) it into the rest of the column.)
My table looks like this:
A B C D E F
ID Category Start-date Due-Date Completion-Date ID+Cat. (Helper column)
The formula in F is simply =$A2 & $B2. The data starts in Row 2.
You will need to replace the columns with yours.
Please let me know if this is what you were looking for.

For dates with missing data, take average of values from closest dates

I have sporadically collected data for stream nitrogen levels. For dates where nitrogen levels are not available, I'm hoping I can use an Excel formula that will estimate the value by calculating the average of nitrogen levels from the two closest dates.Note that nitrogen is not correlated with flow (or other water quality parameters) and there is no trend so I can't use a regression equation to estimate values.
Below is an example of what the table looks like for columns A, B, and C, and rows 1 (header) to 7. Column B contains the real data (note that I inserted 'no value' for illustrative purposes). Column C is what I would like to have calculated. Because I have thousands of rows of data, manually entering each of these formulas is not an option.
Date_______Actual Value______Desired Calculation
1/1/2012_______0.15__________=B2
1/2/2012_____[no value]_______=AVERAGE(B2,B5)
1/3/2012_____[no value]_______=AVERAGE(B2,B5)
1/4/2012_______0.17__________=B5
1/5/2012_____[no value]_______=AVERAGE(B5,B7)
1/6/2012_______0.23__________=B7
=IF(B1<>"",B1,VLOOKUP(MAX($A$1:$A$4),$A$1:$B$4,2,0))
Misread the question the first time.
Test to see if B1 is equal to "" or not. If it is empty then perform the VLOOKUP searching for the max value of column A (most recent date), and then use the value for the adjacent column (2).
This will not cover the case where the most recent Date has no value in column B. I will return "" in that case.
TREND Option
Based on your comments and the use of some helper cells you could do the following. Make a small table off to the right somewhere of just your known dates and your known values from B. We can populate this table using the following formulas. Let arbitrarily put this table in columns F and G.
in F2 use:
=IFERROR(INDEX($A$2:$A$1564,AGGREGATE(15,6,(ROW($B$2:$B$1564)-ROW($A$2)+1)/($B$2:$B$1564<>""),ROWS(B$2:B2))),"")
This will pull the dates in order that they appear with values in B that are not "". Then in G2 put the following formula in which will pull the associated value from B
=IFERROR(INDEX($B$2:$B$1564,AGGREGATE(15,6,(ROW($B$2:$B$1564)-ROW($B$2)+1)/($B$2:$B$1564<>""),ROWS(B$2:B2))),"")
Both those formulas are currently set up to work with a header row and data starting in row 2.
once we have the helper table set up, you can set up a TREND function, which is a line of best fit through all your known points. You can pick the point on this line for dates with no value in B. In C2 you would add:
=IF(B2="",TREND($G$2:$G$3,$F$2:$F$3,A2),B2)
you would copy this formula down. It checks to see if B is blank. If it is then it pulls a value for B from the trend line. If it is not blank, then it will use the value in B.
AVERAGE Option
Again using the helper table in the same spot. This one gets a little uglier. In C2 place the following and copy down
=IF(B2<>"",B2,IF($A2<$F$2,$G$2,IF($A2>$F$3,$G$3,(INDEX($G$2:$G$3,IFERROR(MATCH($A2,$F$2:$F$3,1),1))+INDEX($G$2:$G$3,IFERROR(MATCH($A2,$F$2:$F$3,1)+1,2)))/2)))
The first thing it does is check for a blank value in B. If there is no blank then it uses the value in B2. If there is no value in B2 it then proceeds to check the date of the blank against the first date in your helper table. If it is less than that first value, it uses the first value of B since there is nothing to average it with. I then proceeds to do the same to see if the date exceeds the last value in the table. (this is currently hard coded). If it exceeds the last date in the table it uses the last value for B. the last option for the date is for it to be in the table. It take the average between the date prior to the date and question and the next date with a value.
Optional version where you dont have to hard code the last values of helper table, but you still need to hard code the range of the helper table to meet your needs.
=IF(B3<>"",B3,IF($A3<$F$2,$G$2,IF($A3>MAX($F$2:$F$3),VLOOKUP(MAX($F$2:$F$3),$F$2:$G$3,2,0),(INDEX($G$2:$G$3,IFERROR(MATCH($A3,$F$2:$F$3,1),1))+INDEX($G$2:$G$3,IFERROR(MATCH($A3,$F$2:$F$3,1)+1,2)))/2)))
TREND Between only two points
So I adjusted the formula a bit on this one. Its kind of a mix of the trend and previous options listed above. I also made it automatically selecting the end values of your table, so now you just have to copy your table down as far as you need. Its also works on the premise that only your data value in B are present, no numbers below your last row.
=IF($A2<$F$2,$G$2,IF($A2>=MAX(OFFSET($F$2,0,0,COUNT(B:B),1)),VLOOKUP(MAX(OFFSET($F$2,0,0,COUNT(B:B),1)),OFFSET($F$2,0,0,COUNT(B:B),2),2,0),TREND(OFFSET($F$2,IFERROR(MATCH($A2,OFFSET($F$2,0,0,COUNT(B:B),1),1),0)-1,1,2,1),OFFSET($F$2,IFERROR(MATCH($A2,OFFSET($F$2,0,0,COUNT(B:B),1),1)-1,0),0,2,1),$A2)))
So basically TREND function is a line of best fit through known points. if your know points do not all sit in a straight line it figures out what straight line passes near them minimizing the distance they are from the line. If we limit the points it using to make its line to only 2 points, then the line has to pass through those two points. Remember, the helper table is a list of all known points.
So basically what the formula doing is checking to see if the date is less than or equal to the first known point on the helper table. If it is, use the value from the first known point in the table. If its not, check to see if the date is greater than the last date in the table, if it is lookup the last known date in the table and return the corresponding table. If neither of these cases is true then the date must be in the table. That means we can get two points from the table and their corresponding values to use in the trend function. We feed the TREND function a an array of 2 known X and 2 Know Y values, and then supply it with an X value we are interested in. In this case X would be the dates, and Y would be the values in the second column.
Revised Helper table
In F2 use this formula:
=IFERROR(INDEX(OFFSET($A$2,0,0,COUNT(A:A),1),AGGREGATE(15,6,(ROW(OFFSET($A$2,0,1,COUNT(A:A),1))-ROW($A$2)+1)/(OFFSET($A$2,0,1,COUNT(A:A),1)<>""),ROWS(B$2:B2))),"")
and G2 use this formula:
=IF(F2="","",INDEX(OFFSET($A$2,0,1,COUNT(A:A),1),MATCH(F2,OFFSET($A$2,0,0,COUNT(A:A),1),0)))
and if you want to verify how far down you want to copy your helper table, you can put this in lets say I3:
=COUNT(B:B)+1
Now these update that are using the count(A:A) or B:B require that no other numbers be above or below your data in the A or B column.
UPDATED Average
I also tweaked the average formula to give this option as well.
=IF($B2<>"",$B2,IF($A2<=$F$2,$G$2,IF($A2>=MAX(OFFSET($F$2,0,0,COUNT($B:$B),1)),VLOOKUP(MAX(OFFSET($F$2,0,0,COUNT($B:$B),1)),OFFSET($F$2,0,0,COUNT($B:$B),2),2,0),AVERAGE(OFFSET($F$2,IFERROR(MATCH($A2,OFFSET($F$2,0,0,COUNT($B:$B),1),1),0)-1,1,2,1)))))
Example results (note rows 14-69 have been hidden so you can see what is happening around row 75.

Resources