Excel function for averaging over an increment - excel

I have a large table in excel with Column A running from 0 to 120 with increments of ~0.08 (This puts the last cell at 1441). I need to condense the table into increments of just 1. I need a function that can average the values from 0-1 and then be able to drag that function down so that the next cell references the next ~12 cells after the first. For Example: I need to average values from A1:A12, then when I drag the formula down 1 cell, it averages A13:A25, and so one.
Sample Data

=AVERAGE(OFFSET($A$1,12*(ROW()-1),0,12,1))
ADDED IN RESPONSE TO SAMPLE DATA
In cell H2 to get averages of column B you can use the formula
=AVERAGE(OFFSET($B$1,12*(ROW()-2)+1,0,12,1))
In cell I2 to get averages of column C you can use the formula
=AVERAGE(OFFSET($C$1,12*(ROW()-2)+1,0,12,1))
And so forth.

Related

Calculating Averages of every 6th cell VBA

I'm looking to calculate the average of a series of cells across multiple tables on the same spreadsheet.
Each manager has a table and in each table, there are a number of statistics e.g. Total Activity, Outbound Calls & Credit. Each table is situated one under the other e.g. Danny's table might be situated on rows 1- 5, Ann's 7-12, Katie's 14-19. I need to find the average for each statistic and output it to my summary page.
I've tried using Application.WorksheetFunction.Average but could not get it working as the range is scattered among various rows. I do however know that each variable appears in every 6th row so I tried For i = 2 To lastRow Step 6 which outputted the values into cells and calculated the averages based on that cell range but I'd rather have something more direct if possible.
Could anyone offer a valid solution to this?
Sample of data beneath. looking to get the average for each of the 4 variables.
Alternative 1
If there are other values than the values you want an average of in column B, you can use SUMPRODUCT.
Enter this formula in any cell in any other column than column B. It will calculate an average of every 6th value starting on row 2.
=SUMPRODUCT(B:B*1*NOT(ISBLANK(B:B))*(MOD(ROW(B:B),6)=2))/SUMPRODUCT(1*NOT(ISBLANK(B:B))*(MOD(ROW(B:B),6)=2))
B:B Array of all values in column.
1*NOT(ISBLANK(B:B)) Array of 1 or 0, 1 on non blank cells in column B, 0 for blank cells.
1*(MOD(ROW(B:B),6)=2) Array of 1 or 0, 1 on row 2, 8, 14 and so fourth
SUMPRODUCT(B:B*1*NOT(ISBLANK(B:B))*(MOD(ROW(B:B),6)=2)) sums all non blank cells in column B on every 6th cell starting at row 2.
SUMPRODUCT(1*NOT(ISBLANK(B:B))*(MOD(ROW(B:B),6)=2)) counts all non blank cells in column B on every 6th cell starting at row 2.
To speed up the formula you can replace B:B with for example B1:B100 depending of the number of rows that have values.
Alternative 2
If there are nothing but values you want an average of, then you can use SUBTOTAL as suggested by Dominique. =SUBTOTAL(1,B:B)

Excel - Dynamic array function with Offset/Max function

I have Excel where I sum data from green table (Table 2) according Column1 and Month (sum is in Column 3). Month in column A is generated by function SEQUENCE and header is taken from blue table. in "B2" is formula =SUMIFS(Table2[Column2];Table2[Column1];B1#;Table2[Month];A2#)
Thanks to the # formula spills to whole range "B2:D13". So far everything is perfect. But now I need to use MAX function to get MAX value for every row. But when I refer to the range by # then it will take the whole range "B2:D13" is there any way, how to spill max formula to every row, but reference only on concrete row?
use MAXIFS with OFFSET and SEQUENCE. Put this in E2 and it will spill:
=MAXIFS(OFFSET(B2,SEQUENCE(ROWS(B2#),,0),0,1,3),OFFSET(B2,SEQUENCE(ROWS(B2#),,0),0,1,3),"<>")

Excel formula: how to SUMIF values meeting certain condition until blank cell

I need to sum values in column A that meet certain criteria in column B until the next blank cell. The image (link above) shows the result I need: sums of all "A" for each three of the batches. I'm using this formula to calculate a total sum for each batch, and it works fine:
IF(A3="";SUM(A$1:A2)-SUM(C$1:C1);"")
But when I try to add SUMIF condition to this formula it doesn't work:
=IF(A3="";SUMIF(B:B;"A";A$1:A2)-SUM(D$1:D1);"")
What am I doing wrong?
Sum if requires that the range sizes be the same.
Put this in C2 and copy down:
=IF(B3="",SUMIF($B$2:$B2,"A",$A$2:$A2)-SUM($C$1:C1),"")
If the value in B in the next row is a null string then it will do the SUMIF, if not it returns a null string.
The SUMIF is being done on all the values from row 2 to the row in which the formula is being placed. We are then subtracting the already counted values above where the formula is placed in column C to get the new sum.

Excel Auto number row based on criteria

I'm trying to create a spreadsheet in excel which creates a sequential number in a column (B) depending on the contents of another column. Currently, there are two possibilities of what could be in Column A ("BI" or "GF"). So I want the data to look like this
COL A COLB
BI 1
BI 2
GF 1
BI 3
GF 2
GF 3
BI 4
BI 5
I've tried several attempts to do this but can't seem to find a solution. Any help would be greatly appreciated.
In B2, try this formula:
=CountIf(A$2:A2,A2)
Try to use the offset equation.
The first cell in COL B will look similar to this:
=COUNTIFS(OFFSET(A$1$1:A1,0,0),A1)
The second should look like this:
=COUNTIFS(OFFSET(A$1$1:A2,0,0),A2)
Drag this down in Col B as far as desired. If you are using a table this should autofill.
Explanation:
Essentially you are using the OFFSET formula to create a dynamic range.
The A$1$ serves as the start of your range by making this an absolute reference and the A1 will serve as the end of your range.
By making the ending cell a relative reference, the array the COUNTIFS function search will never go beyond the row the of the cell the formula is relative of.
In your example, the formula in the first row in Col B would result in 1. The reason is the OFFSET returns the array of A$1$:A1 and the COUNTIFS searches through that array and returns a count of all cells equal to A1 which is "BI".
The second row retains the original starting cell for the array of A$1$ however the end of the array is A2. So the COUNTIFS function sees the new array to search through to be A$1$:A2. The COUNTIFS then searchs through each cell equal to A2 which like A1 is "BI". There are two cells equal to "BI" in the new array and thus the reult is 2.
How this works like you want is displayed in the third row of Col B.
The OFFSET functions simply expands the array size to A$1$:A3. The COUNTIFS will work as it normally does, it takes the array, called the criteriarange in Excel, and performs a count for all items that equal A3. A3 in this case is equal to "GF" and in the array A$1$:A3 there are two cells equal to "BF" and one equal to "GF".
Hope this helps!

Return a cell reference for use in a formula

I have an excel workbook with paired data sets of the type [columnA=time:columnB=data]
There are thousands of data points.
What I'm looking to do is this: I have a table of time values on a separate sheet. I want to find the corresponding cell in the data column of the data worksheet (column B) and return an average of the values of 5 cells before it and 40 cells after it.
By searching the questions I came up with this formula to return a cell address of the exact value I'm looking for, however I can't put it into an average formula.
=CELL("address",INDEX('EMG Data'!B1:B10000,MATCH(C5,'EMG Data'!A1:A10000,0),1))
C5 is the time value I know I want to get the data value pair for.
use a combination of average, offset and match instead, offset will allow you to change the number of rows/columns in the range:
=IFERROR(AVERAGE(OFFSET($B$1,MAX(MATCH(C5,A:A,0)-6,0),0,46)),"SOMETHING IS WRONG")
MATCH
MATCH() will find the right value in column 1 and return its position in A:A.
OFFSET
To OFFSET to the corresponding row compared to cell B1 you should do MATCH()-1 (otherwise a Match in cell A1 yielding a 1 will OFFSET B1 by 1 row thus showing the value of B2!!
You want to offset B1 by 0 columns so put that as third parameter.
Moreover you want to have the 5 rows before as well so this becomes MATCH()-6, to avoid trying to retrieve data from rows with negative row numbers we use MAX(MATCH()-6,0).
As you want the 5 cells before and the 40 cells after you want the height to be 5 + 1 + 40 = 46 cells completing the OFFSET parameters with that number for the height parameter
AVERAGE
Final step is to get the actual average, as the OFFSET() function gives back a range of cells this is seen as a normal range input for the AVERAGE function.
IFERROR
In case the value you look for is not found in column A:A than MATCH() will give an error which will work its way through the nested functions, Most of us would capture such event with IFERROR() and transform the error into something user friendly, or have an alternative function/result in that case

Resources