Sum of row n through last row - excel

I want to create a TOTAL row at the top of my spreadsheet. In this row, each cell should be the SUM of the values in the column below the TOTAL row.
So for example, if the total row is Row 1, cell A1 should be the SUM of A2 through the last row in column A. The number of rows in the spreadsheet will grow over time, so I can't just say SUM(A2:A500) because eventually there will be row 501, 502, 503 etc.

If you want something that just works in Google Spreadsheets (as the title suggests), you can use open-ended ranges:
=SUM(A2:A)
In Excel, you can specify the maximum rows for that version; for example, for 2007 and 2010:
=SUM(A2:A1048576)
This will work in Google Spreadsheets as well, and is beyond the current theoretical row limit in GSheets (400000)*.
Edit: *The quoted limit of the new version of Sheets is actually now 2 million cells.

Try this
=SUM(OFFSET(A1,1,0,ROWS(A:A)-1,1))
Works in both Excel and Google Docs
One downside: by using OFFSET the formula becomes Volatile ie is calculated every time the sheet calculates irrespective of data change.

One way you can do this in both Excel/Google Spreadsheets is to add a dummy column with a single value at the top (and all blanks for the remainder of the column).
You can then do a SUMIF to summarize all values except the one which is not "" - which should just be the cell A1 - put the following in B1, with whatever numbers below B1 you want and anything in A1.
=SUMIF(A:A,"",B:B)

=(B3+C3+D3+E3+F3+G3+H3+I3+J3+K3+L3+M3)
This worked for me. 3 being the row number
When you Drag the box downward the formula transfers down and changes the row number automatically for each row.
After I put another heading several rows down
adding the word SUM into the formula worked.
=SUM(B19+C19+D19+E19+F19+G19+H19+I19+J19+K19+L19+M19)
Not sure if it was necessary. But just copy pasting the first formula I used into the lower segment made an error message.

Related

Excel formula to find last non blank cell in a column starting on a certain row

So I've got a column of data that I want to count the non blank cells after a certain row.
Here's an example of what I have:
So, in this example, I would like to start counting non blank cells in column A starting on row 13 (which would be a total of 4). If you look at the formula I have entered into cell D12 I can get the value I'm looking for with this formula:
=COUNTA(A:A)-11
I could use this formula:
=COUNTA(A13:A16)
but the point is the last cell with data in it can change due to entering different amounts of data in the column.
But I'm wondering if there is a different formula I could use that would count non blank cells from a certain row down regardless of the amount of data I enter into the column from a certain row down using an open ended range, kind of like this:
=COUNTA(A13:A)
This formula doesn't work but it kind of illustrates what I tried to do that didn't work.
from my comment above:
Well, you could always get the last used row dynamically and incorporate that, not sure what your benefit is over using the last row:
=COUNTA(A13:INDEX(A:A,LOOKUP(2,1/(A:A<>""),ROW(A:A))))
This makes it somewhat "open" ended I guess. Unfortunately it isn't GS =)

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 :)

Count values in column ignoring duplicates

Not really an Excel user, but what seemed simple has turned out to be very difficult for me. I am in trouble as I can't come up with a nice and clean (or any) way to get it working.
What I have here:
I need to create a new columnn that would tell the amount of employees in each occupation while ignoring the duplicates (highlighted).
The amount of names formula is working, so maybe this can be used ? Or maybe it's just in the way and should be cleared.
It's just:
=COUNTIFS(A:A;A2)
Tried searching for quite a while did not find anything suitable. Any help or advice would be much appreciated. I hope I explained it in clear manner.
Thank you
Without helper columns:
Two options, D2:
{=SUM(--(FREQUENCY(IF($B$2:$B$9=C2,MATCH($A$2:$A$9,$A$2:$A$9,0)),ROW($A$2:$A$9)-ROW($D$1)+1)>0))}
Or put in E2:
{=SUMPRODUCT((($B$2:$B$9=C2))/COUNTIFS($B$2:$B$9,$B$2:$B$9&"",$A$2:$A$9,$A$2:$A$9&""))}
Notice both are array formulas and should be entered through CtrlShiftEnter
SUMPRODUCT 'Deals' in Arrays 3
You might have employees with the same name (David, Michael) in different occupations (Tech & Worker, Tech & Economy). To distinguish those from each other, in B2 you can use:
=SUMPRODUCT((A$2:A$21=A2)*(C$2:C$21=C2))
In D2 you can use:
=SUMPRODUCT((1/B$2:B$21)*(C$2:C$21=C2))
Distinct Employees Occupation Count
with a helper column
Unique and Distinct values are tricky. Using a helper column is beneficial for identifying either one of these when coupled with an expanding range:
=SUMPRODUCT((A2=$A$1:$A1)*(C2=$C$1:$C1))
Relative Rows: ^ ^
Paste to cell E2.
Copy Drag the formula down from the where pasted.
The relative row numbers identified above well increase as the formula is copy dragged down. This creates a larger and larger range for comparison. An expanding range.
In this case the range that is expanding is the range of already checked values. Many times the result range is expanded and tested against to eliminate posting duplicates of already posted results in subsequent rows of the results list.
The helper column's value is how many times the name and occupation pair has previously appeared. Zero previous appearances tells us this is the first occurance. We will only count the zeros (first occurance) in the main formula.
The main formula for counting distinct employees in each occupation:
=COUNTIFS( $C$2:$C$9, C2, $E$2:$E$9, 0)
Paste to cell D2.
Copy Drag the formula down from the where pasted.
Here we count all the rows for this row's occupation where the occupation matches the range of listed occupations and for that particular row in the list of occupations, the helper column row value is zero.
Add a final column which is the concatenation of the prior 3 columns then use
=SUMPRODUCT(1/COUNTIF(D2:D9,D2:D9))
There is a good explanation of this formula here. Basically, values that appear once will count as 1. Values that appear more than once will appear as fractions of their total occurrence count and be summed to 1.
If you convert your data to an Excel table by selecting a populated cell in the range and pressing Ctrl+T, then formulas will auto-populate down last column. You can then reference the table columns in the formula and you won't need to amend the formula as you add rows.

Formula referencing cells as index not working

I have an Excel spreadsheet made up of 2 sheets.
The first sheet is just data that has been imported.
The second sheet is a number of formulas that will extract various counts and totals from the first sheet.
The first formula is as follows
=COUNTIFS(Raw_data!B2:B1780,"Y7",Raw_data!F2:F1780,"M",Raw_data!G2:G1780,"D",Raw_data!L2:L1780,"EN")
It looks at 4 columns in the first sheet and counts the number of records that meet the criteria in each column.
This works fine. However, the number of rows in the raw data (1780) could vary. I have a found a formula that works out the number of rows in the raw data and that works OK. So what I was trying to do, was instead of having the number of rows fixed at 1780, have the above formula get the the number of rows from the cell that has done the row calculation.
So I ended up with this
=COUNTIFS(Raw_data!B2:INDIRECT(CONCATENATE("B",G3)),"Y7",Raw_data!F2:F1780,"F",Raw_data!G2:G1780,"D",Raw_data!L2:L1780,"EN")
where G3 contains the calculated number of rows. (I've only done this for raw data column B at present, as I wanted to prove it first). Excel comes back with #VALUE! in the formula cell, no matter what variations I try. I suspect the answer is very simple, but at present it eludes me.

Formula with dynamic variables in excel

I have an Inventory of boxes as an excel sheet with two columns(Total and Usage). The column on the right(total) has a value which shows the initial number of boxes. In the left column(usage) I give the number of boxes that I remove from the stock on a date. I want the right side column(Total) to be updated automatically.. Meaning if the total value at the start is 50 and I use 4 boxes then i want the cell in the total column at that row to show the new total
Example My total value is initially 50(B2) and i use 4 boxes(A3). I want B3 to show the new total... As i keep adding usage values in column A i want column B to be updated as (previous total - new usage) How to do this in excel? I dont want to type in the formula in each cell and i dont know if i can assign varaibles to cells. Is it possible?
I am assuming you want to use subsequent rows to record each withdrawal of some boxes? You need to enter the appropriate formula in each cell of the total column. So in B3, put =B2-A3. Then copy-paste that to all cells below in col B, Excel will paste a formula whose cell references are relative to the cell the formula is pasted to. Alternatively there is a mouse drag gesture that's even faster to fill a column with a formula.

Resources