Excel - Writing proper SUM formula - excel

I am supposed to sum up the total highlighted numbers and add the sum in the red marked cell beside the average number. I am using a basic SUM formula to add the cells. I have a couple thousand lines to do this with and I have to manually change the SUM formula to include the right ranges (as some have 4 numbers to add up, some have 3 and others have 2). Is there a way to write the formula so it SUMS all the numbers up until the Average line above it? So I can use the same formula throughout my sheet and not have to change it for every line?

No need for Array formulas.
I will assume you are starting in H2. As per your photo in the discussion
=IF(E2 = "Average",SUMIF($E$1:E1,"<>Average",$G$1:G1)-SUM($H$1:H1),"")
And copy down.

You could use a variable range within a SUM function, using INDEX and MATCH to find the previous instance of Average.
Something like this - an array formula, so enter with Ctrl+Shift+Enter:
=SUM(B3:INDEX(B$1:B3,IFERROR(MATCH(2,1/(A$1:A3="Average")),0)+1))

Related

How to sum column until current row?

I'm using an Excel table to sum some values. On a certain column, I want a running total (that is, a sum of all values previous and up to the current row). Doing that on ranges is easy, all I need to do is use an absolute cell address for the start of the range (using the $ notation) and use a relative address for the current row.
However, using tables, things get messy - the notation for ranges in tables use the [[]] syntax. Is there a way to denote a range beginning at the top of the column until the current row?
Use the Header as your starting point:
=SUM(Table1[[#Headers],[Num]]:[#Num])
I suggest you go with #ScottCraner but another option is:
=SUM(INDEX([Num],1):[#Num])
This can also be adapted to allow you to sum to any row, not just the current one. e.g. to sum the first 3 rows:
=SUM(INDEX([Num],1):INDEX([Num],3))
You want a separate column with the totals up to this row? That is the previous total plus the current value.
Or, assuming column A has the values and B has the running total :
cell B1 =A1
cell B2 =B1+A2
and copy that formula down as far as you need

How to find last number in row minus second to last number in row

I have a spreadsheet that I'm using to try and keep track of google keyword rankings, but I can't figure out how to track the last change in keyword ranking, meaning the last cell in the row MINUS the second to last cell in the row. I've included a picture on what I'm trying to accomplish. The formula would take, for example, in J3-I3 to get the last change of 4 shown in D3.
Right now I have this code:
=(LOOKUP(2,1/(3:3>0),3:3))-LOOKUP(9E+300,B3:INDEX(B3:J3,MATCH(9E+300,B3:J3)-1))
Which is fine, but I need to keep changing the cell references is. Is there any easier way to accomplish this?
You can use just INDEX(MATCH()) and refer to the full row.
=INDEX(3:3,MATCH(1E+99,3:3))-INDEX(3:3,MATCH(1E+99,3:3)-1)
If you have, say, 12 columns B="Jan" to M="Dec" with a formula in each, and you need to calculate the difference between the latest month's value and the previous month's value, the formula above does not work if any columns are blank but with formulas, or until you have a value for each of the 12 months.
If you want to calculate, say, Jun minus May when Jul to Dec are blank except for their formulas, this formula (for row 4) will do it for whatever the latest month with a numerical value is:
=INDEX(4:4,MAX(IF(ISNUMBER(B4:M4),COLUMN(B4:M4))))-OFFSET(B4,0,SUM(IF(ISNUMBER(B4:M4),1))-2,1,1)
It must be entered with Ctrl+Shift+Enter.
#ScottCraner has provided an answer with the right logic, which is to
locate the second last and last number in each row, and then perform a
simple subtraction between the two.
INDEX+MATCH is one way of solving the question, but in this case, given that all data are stored in a table, and to add the flexibility of
1) moving the table around or across worksheets;
2) entering numeric value in the same row outside of the table;
without incurring errors, I've used OFFSET+COLUMNS instead.
Please note in my example I have given a name to the table, called it Tbl_WordRk, and I have added some data (in the gray area) for testing purpose.
Basically, OFFSET works in similar logic as INDEX, with a known starting point (such as B3 in my example), it will find the value (or even a range of values) in another row or column as long as you know the relative position of the value compared to the starting point. For example, if your starting point is cell A1, the following OFFSET function will return the value in cell D8.
=OFFSET(A1,7,3) which is interpreted as 7 rows down and 3 columns to the right of cell A1
COLUMNS finds the total number of columns of a given range, which is perfect for finding a column position within a table. The following formula will return number 7 which is the total number of columns of the table in my example, but please note it is NOT the relative column position of the last column to cell B3.
=COLUMNS(Tbl_WordRk)
You need to add -1 to the above formula to find the relative column number of the last column from B3. And therefore, adding -2 will return the relative column position of the second last column from B3.
So the final formula in cell B3 in my example is
=OFFSET(B3,,(COLUMNS(Tbl_WordRk)-2))-OFFSET(B3,,(COLUMNS(Tbl_WordRk)-1))
Then you just drag it down to the last row.
Just one more advice on the conditional format of your example, I would prefer not to show a green upward arrow if there is no change in the word ranking. If you know how to edit an existing conditional formatting, here is how to set it:
Cheers :)

How only average cells that cell to the left contains a number

I need formula help
using cells a1 - ce1, various data, but about every 3rd to 5th column is a column containing a %. I need to average by row, the % but only if the cell to the left contains a number(even 0).
You can use the formula AVERAGEIF() to achieve this. You can find further information on its use here: https://www.techonthenet.com/excel/formulas/averageif.php

Excel 2010: Counting cells with adjacent cell blank

I have data in rows where each column represents a day, some of which are blank and some of which have numbers. I want to "scan" down the row, comparing each cell with the one before to the left of it (or the one 2 spaces left of it, etc). For example, I want to sum the number of cells (days) with a blank in the cell before it. Or, I want to sum the number of cells that are greater than the cell to the left of it. I can't figure out how to dynamically compare to the prior column using addresses that change with each cell.
This is from what I understood from your Question:
If you refer to the screenshot below, you want to count Columns B to H if the column has a number and the column to the left is blank.
So, if this was just one column, we would write the formula as:
=COUNTIFS(B3,">0",A3,"")
Now since you want to do this for a range of columns (an array of cells), you need to do something like:
=COUNTIFS(B3:H3,">0",A3:G3,"")
and accept with a Ctrl + Shift + Enter.
So the formula would be displayed as:
{=COUNTIFS(B3:H3,">0",A3:G3,"")}
Array formulas are perfect for this task. I can't give you a lecture on the topic but you should read on it. Basically, you can select multiple cells in a range and act as if it was one cell.
For example, you could do something like this:
=SUM(IF($A$1:$A$100="", 1, 0))
When you enter array formulas, be sure to hit CTRL + SHIFT + ENTER in the formula box to signify that you want Excel to treat this formula as an array formula. Otherwise you will not get the expected results.
Using this method you can do any kind of comparison. Sometimes it helps to see how Excel treats the formula. You can select part of the formula in the formula editor and hit F9 to see what this segment computes to according to Excel.

Advanced Excel: Sum of relative cells of a category

I’m a designer. I have a list of tasks, with hours, and I’ve split them into milestones. I want to count the number of hours for each milestone.
Here’s a picture:
In other words: I want to look at the value in the M column, if it’s 1, I want to get the cell across it, then repeat down the rows, and sum the whole lot.
See if you can figure that one out with the least cell wastage! :) (This is Numbers for Mac, so no macros or vbscript or what-have-you.)
In Excel the SUMIF formula can be used.
Assumption: In picture above, the 'Hours' label is in cell A1
The formula for 'Milestone 1' in cell E2 would be:
=SUMIF($C2:$C11,RIGHT(E1,1),$A2:$A11)
The syntax of the formula is:
=SUMIF(range, criteria, sum range)
The criteria is determined by using the last character in the 'Milestone' heading.

Resources