Calculations at the bottom of each column - excel

I am using an excel spreadsheet to keep track of some data.
I calculate median and quartile values for each column at the bottom of those columns (rows 15, 16, 17). However, I want to be able to keep adding new values into columns without changing the range of my median/quartile formula. I know I can select the whole column in my formula if I had the formula in a different cell than the column I am making calculations on.
I am wondering if there is a way to exclude the rows with my median and quartile formulas from my calculations. As I enter more data, those locations will also increase and I couldn't figure it out.

So if we know the number of blank lines to be two, before we do the median, then =median(INDIRECT(CONCATENATE("B2:B",text(row()-3,"#"))))
works, by constructing the range of column B fed to the median function to be B2 through B + whatever number is 3 up from the row where the formula sits. For the IQR presumably 3 must be increased.

Related

Excel formula and drag down

I need to calculate Stand BA (highlighted on the right). This average is obtained by taking the sum of each plot's BA/ac value and dividing by the number of plots (for this example, there are 11 #1024 plots). The number of plots is always different. What formula could I use to apply the StandBA column so that I can drag it all the way down by plot number?
Try using =AVERAGEIF(A:A,A2,T:T).
It will return the average value from column T, and rows having the value of A2 (then A3, A4...) in column A will be the only ones to be taken into consideration for the calculation of the average value.
EDIT:
Use =IF(A2=A3,"",AVERAGEIF(A:A,A2,T:T)) if you want only the last rows of your Plot Id to contain the average formula (as shown on the screenshot in column U).
Example with columns A:C, formula pasted into C2 and dragged down to the last row.

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 Sum X amount of columns depending on a value in another cell

Is there a way that you can use sum() in excel and that sums up x amount of columns depending on number given in another cell.
See below for example
Example of how it's today
In this picture I have columns B:M were I put in Actual figures.
And in columns T:AE I have budget figures.
In this example I have actual figures JAN-MAY and would like to compare them vs budget JAN-MAY.
How I do today is that I go in to column AF and drag so it's =SUM(T6:X6) so it only takes T:X in this case.
But I would like that cell AF has a formula in it were it looks at cell AH:3 and sees that it's number 5.
Therefore AF should sum(T;U;V;W;X(5columns))
Hope you understand my problem and have a solution!! :)
You can use the OFFSET function to determine the number of columns to SUM. In your example, AH3 is your offset amount.
In AF6 you can place this formula:
=SUM(T6:OFFSET(T6,0,AH3-1))
Which breaks down to
=SUM(T6:OFFSET(Start at T6, Offset 0 rows, Offset columns the value of AH3 and subtract one for a total of five columns))

Sum values across a row if they are in certain columns, and if adjacent cells have a specific value

Link to data screenshot: https://imgur.com/a/CrRLb6d
I am working with an excel file that has a recurring group of 4 columns (see image: column headers are Time, Med1, Med2, Med3). On the left, in column B, I want to have the sum of the values on a row, but the only values that should be summed are those that meet the criteria:
The value is in a Med1 column (all columns that have the Med1 header), and;
The adjacent Time value on the same row (1 column to the left of a Med1 column) is 1.5 or greater.
So, for example looking at row 10 (highlighted in the example), the Med1 values in E10 and I10 should be summed in B10 (because their respective Time values in D10 and H10 are 1.75 and 1.5, respectively, i.e. >=1.5), but not the Med1 value in M10 (Time value in L10 is 1.25 which does not meet the second criterion above).
Some additional info:
Each of these ‘blocks’ has a fixed width of 4 columns, without gaps in between (in the actual excel file, there are 240 of these blocks).
The pattern of Time continues like in the example shown, always starts at 0, one row lower compared to the previous block.
What I have tried: SUMIF, SUMIFS and INDEX functions, but I get #VALUE errors if I try to combine criteria (especially as it is not 1 Time column value that needs to be checked for a row, but multiple Time column values across a row).
Previously, I just wanted to sum all Med1 value on a row (regardless of the adjacent Time value), like this:
=SUMIF($D$2:$O$2;"Med1";D3:O3)
However, with the second criterion of the adjacent Time value, I cannot seem to get it to work. Any help is appreciated!
If the blocks are all right next to each as shown in your image, and the value you want to sum is always 1 cell to the right of the time value, and only the time values can be >= 1.5 (all of your MedX values are < 1), then this formula would work for you:
=SUMIF(D3:O3,">=1.5",E3:P3)
If it's possible for the MedX values to be >= 1.5, then this more explicit formula should work for you:
=SUMPRODUCT(--($D$2:$O$2="Time"),--(D3:O3>=1.5),--($E$2:$P$2="Med1"),E3:P3)

Need formula operating against a dynamic range copied across a series of cells

I'm creating a grid of correlation values, like a distance grid. I have a series of cells that each contain a formula whose ranges are easy to describe if you know the offset from the first cell, and I'm having trouble figuring out how to specify it.
In the upper left hand cell (R10), the formula is CORREL(C2:C21,C2:C21) -- it's 1, of course.
In the next column over (S10), the formula is CORREL(D2:D21,C2:C21).
In the next row down (R11), the formula is CORREL(C2:C21,D2:D21).
Of course, S11 would contain CORREL(D2:D21,D2:D21), which is also 1. And so on, for a roughly 15x15 grid.
Here's a graphical representation of the ranges involved:
C2:C21,C2:C21 C2:C21,D2:D21 C2:C21,E2:E21
D2:D21,C2:C21 D2:D21,D2:D21 D2:D21,E2:E21
E2:E21,C2:C21 E2:E21,D2:D21 E2:E21,E2:E21
Whenever I add a new data row, I have to manually update several formulas. So, I'd like the last non-blank column number (21, in this case), to be dynamically determined, such as with COUNTA(C:C). Ideally, I'd like the formula to calculate the row offsets, too, so that I can drag one formula across my entire range.
What's the best way to accomplish this? I think OFFSET might be a component in the solution, but I haven't had success getting it all to work together.
Using this simple setup per element of the corr matrix also helps:
=CORREL(INDIRECT("'Risk factors'!"&"T"&G6&":T"&H6);INDIRECT("'Risk factors'!"&"U"&G6&":U"&H6))
With this function I refer to data in another sheet, Risk factors, to correlate rows T and U with each other. I want the ranges of the data to be dynamic so I refer with G6 and H6 in my current sheet to the lenght of the columns (number of rows) which I of course specify in these G6 and H6 cells.
Hope this helps!
I found this formula, while wordy, achieved the desired results. In this example, the data lives in C2:O19. The table I wanted to construct computed the correlation values of all permutations of pairs of columns. Since there are 11 columns, the correlation pairs table is 11x11 and starts at R10. Each cell has the following formula:
=CORREL(INDIRECT(ADDRESS(2,2+(ROWS($R$10:R10)),4)&":"&ADDRESS(COUNTA($C:$C),
2+(ROWS($R$10:R10)),4)),INDIRECT(ADDRESS(2,2+(COLUMNS($R$10:R10)),4)&":"&
ADDRESS(COUNTA($C:$C),2+(COLUMNS($R$10:R10)),4)))
As I found out, INDIRECT() resolves a cell reference and obtains its value.
Let's take a cell, say U12, and look at the range formula in detail. The first INDIRECT is the column given by applying the row offset from R10.
Since Row 12 is 2 rows down from Row 10, ADDRESS(2,2+(ROWS($R$10:U12)),4)&":"&ADDRESS(COUNTA($C:$C),2+(ROWS($R$10:U12)),4) should yield the column that's 2 rows right of Row C, which is E. The formula evaluates to E2:E19.
The second INDIRECT is the column given by applying the column offset from R10. Similarly, since Column U is 3 columns right of Column R, ADDRESS(2,2+(COLUMNS($R$10:U12)),4)&":"&ADDRESS(COUNTA($C:$C),2+(COLUMNS($R$10:U12)),4) should yield the column that's 3 rows right of Row C, which is F. The second formula evaluates to F2:F19.
Substituting these range reference values in, the cell formula reduces to =CORREL(INDIRECT("E2:E19"),INDIRECT("F2:F19")) and further to =CORREL(E2:E19,F2:F19), which is what I'd been using up till now.
Just like a distance table, this table is symmetrical along the diagonal, because =CORREL(E2:E19,F2:F19) equals =CORREL(F2:F19,E2:E19). Each value on the diagonal is 1, because CORREL of the same range is 100% correlation by definition.

Resources